茉莉花间谍未定义

时间:2012-08-19 05:28:23

标签: javascript coffeescript jasmine jasmine-jquery

当我运行我的茉莉花规格时,我收到以下错误:

Error: Expected a spy, but got undefined.

我的coffeescript代码:

  describe "setupForm", ->
    beforeEach ->
      spyOn(Subscription.prototype, 'runSimulation')

    it "calls subscription.runSimulation when form is submitted with number", ->
      Subscription.prototype.runSimulation()
      expect(Subscription.prototype.runSimulation()).toHaveBeenCalled()

我已经将我的错误代码简化为上面的调试,但是我无法弄清楚为什么当我明确地将其称为我的测试时,间谍从未被调用过。我正在其他地方测试该方法,所以我认为错误必须与我如何使用Jasmine Spy有关。感谢。

1 个答案:

答案 0 :(得分:14)

()Subscription.prototype.runSimulation()

结束
  expect(Subscription.prototype.runSimulation).toHaveBeenCalled()