I would like to test what happens in when an event occurs. I’ve just started learning Jasmine and I’m not quite sure how to do this part. Basically, when an event goes off, it should call a function. I want to expect that the function has been called correctly. I’ve been trying to figure this out for quite a while now, so if anyone could help, that’d be great. Here’s what I have right now.
module.exports = function: -> $(window).on 'resize', => @functionToCall() functionToCall: -> console.log "I'm being called!"
Foo = require 'foo' describe 'Testing events', -> it 'should call Foo.FunctionToCall after the window has been resized', -> spyOn($.fn, 'on').andCallThrough() spyOn(Foo, 'FunctionToCall') # I think I have to do something here to mock the event? waitsFor -> Foo.function() runs -> expect($.fn.on).toHaveBeenCalledWith('resize', Jasmine.any(Function)) #Also can't get jasmine.any(Function) to work expect(Foo.functionToCall).toHaveBeenCalled()
I’m pretty sure the issue is that
Foo.function returns an event instead of a
Boolean or a
waitsForPromise). Anyway, thanks for the help.