Jasmine testing coffeescript expect(setTimeout).toHaveBeenCalledWith
- by Lee Quarella
In the process of learning Jasmine, I've come to this issue. I want a basic function to run, then set a timeout to call itself again... simple stuff.
class @LoopObj
constructor: ->
loop: (interval) ->
#do some stuff
setTimeout((=>@loop(interval)), interval)
But I want to test to make sure the setTimeout was called with the proper args
describe "loop", ->
xit "does nifty things", ->
it "loops at a given interval", ->
my_nifty_loop = new LoopObj
interval = 10
spyOn(window, "setTimeout")
my_nifty_loop.loop(interval)
expect(setTimeout).toHaveBeenCalledWith((-> my_nifty_loop.loop(interval)), interval)
I get this error: Expected spy setTimeout to have been called with [ Function, 10 ] but was called with [ [ Function, 10 ] ]
Is this because the (-> my_nifty_loop.loop(interval)) function does not equal the (=>@loop(interval)) function? Or does it have something to do with the extra square brackets around the second [ [ Function, 10 ] ]? Something else altogther?
Where have I gone wrong?