在学习Jasmine的过程中,遇到了这个问题。我想要一个基本功能运行,然后设置超时再次调用自己......简单的东西。
class @LoopObj
constructor: ->
loop: (interval) ->
#do some stuff
setTimeout((=>@loop(interval)), interval)
但我想测试以确保使用正确的参数调用 setTimeout
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)
我收到此错误:Expected spy setTimeout to have been called with [ Function, 10 ] but was called with [ [ Function, 10 ] ]
这是因为(-> my_nifty_loop.loop(interval))
功能不等于(=>@loop(interval))
功能吗?还是它与第二个周围的额外方括号有关[ [ Function, 10 ] ]
?还有别的吗?
我哪里出错了?