Why is Number not a constructor in my Teaspoon/Jasmine spec test?

68 Views Asked by At

I am attempting to test a .js.coffee file and I continually get error:

Failure/Error: TypeError: undefined is not a constructor (evaluating 'Number.isNaN(likesCount)')

I believe I need to include Number in my spec file, how do I do this? I am new to spec testing.

Here is my js.coffee file

class Page.LikeButtons
  constructor: (@el) ->
    Page.handleAjaxOn @el.find('.js-create-like'), (event, data) =>
      @_increaseCountOnPage()

  _increaseCountOnPage: () ->
    likesContent = @el.find('button.like-count.js-show-modal')
    likesElement = likesContent[0].innerHTML.split(' ')
    likesCount = parseInt(likesElement[0])
    like = "Likes"
    if (Number.isNaN(likesCount))
      like = "Like";
      likesCount = 0;
    likesContent[0].innerHTML = "#{parseInt(likesCount) + 1 } #{like}"

$(document).ready ->
  for el in $('.js-like-button-container')
    new Page.LikeButtons($(el))

and here is my spec.js.coffee file

describe 'like buttons', ->
  beforeEach ->
    setFixtures ''' 
      <div class="js-like-button-container" data-taste-id="456">
        <div class="hidden js-hideable-modal"></div>
          <button class="like-count js-show-modal"></button>
        <div class="js-create-like"></div>
        <div class="js-delete-like"></div>
      </div>
    '''

    new Page.LikeButtons($('.js-like-button-container'))

  describe 'when the user clicks to like', ->
    beforeEach ->
      $('.js-create-like').trigger('ajax:success', [{like: {id: 123}}])

    it 'classes the container as current-likes', ->
      expect($('.js-like-button-container')).toHaveClass 'current-likes'

    it 'builds an href for the delete button for the created like', ->
      expect($('.js-delete-like').attr('href')).toEqual(
        '/api/...'
      )
0

There are 0 best solutions below