编程语言
首页 > 编程语言> > javascript – 茉莉花间谍未定义

javascript – 茉莉花间谍未定义

作者:互联网

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

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有关.谢谢.

解决方法:

从Subscription.prototype.runSimulation()的末尾取():

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

标签:javascript,coffeescript,jasmine,jasmine-jquery
来源: https://codeday.me/bug/20190714/1455468.html