Jasmine testing coffeescript expect(setTimeout).toHaveBeenCalledWith
Posted
by
Lee Quarella
on Stack Overflow
See other posts from Stack Overflow
or by Lee Quarella
Published on 2012-11-27T19:49:34Z
Indexed on
2012/11/27
23:08 UTC
Read the original article
Hit count: 285
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?
© Stack Overflow or respective owner