So I have this JS prototype (class) that I'm trying to build jasmine tests for and cannot seem to figure out how to get these tests working.
here's the important parts of the class:
class Calendar extends BasicView
initialize: (options) ->
this.$el = options.el
{@sidebar} = options
this.$('.select-day').click this.display_date
this
display_date: (e) =>
console.log 'display_date called' # <~~ this is printing
... do stuff ...
and the tests I'm writing:
describe "Calendar", ->
calendar = null
beforeEach ->
loadFixtures "calendar/calendar.html"
describe "#initialize", ->
beforeEach ->
calendar = new Calendar().initialize
el: $('.event-calendar')
# just mocking dependency class
sidebar: jasmine.createSpyObj(CurrentlyViewing, ["$"])
it "listens for click event on .select-day", ->
spyOn(calendar, 'display_date')
calendar.$('.select-day:eq(1)').trigger 'click'
expect(calendar.display_date).toHaveBeenCalled()
When I run the test I get Expected spy display_date to have been called.
despite the fact that the actual method IS getting called. I know it's just that what I'm spying on isn't the instance of Calendar
that I initialized, but I can't figure out how or why.
I'd appreciate any help anyone can give me.