最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jasmine Spy Undefined - Stack Overflow

programmeradmin4浏览0评论

When I run my jasmine specs I get the following error:

Error: Expected a spy, but got undefined.

My coffeescript code:

  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()

I have simplfied my erroring code to the above for debugging, but I can't figure out why it is saying the spy is never called when I'm explicitly calling it my test. I am testing the method in other places, so I think the error has to be with how I am using the Jasmine Spy. Thanks.

When I run my jasmine specs I get the following error:

Error: Expected a spy, but got undefined.

My coffeescript code:

  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()

I have simplfied my erroring code to the above for debugging, but I can't figure out why it is saying the spy is never called when I'm explicitly calling it my test. I am testing the method in other places, so I think the error has to be with how I am using the Jasmine Spy. Thanks.

Share Improve this question asked Aug 19, 2012 at 5:28 JohnJohn 4,3825 gold badges34 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

Take the () off the end of Subscription.prototype.runSimulation():

  expect(Subscription.prototype.runSimulation).toHaveBeenCalled()
发布评论

评论列表(0)

  1. 暂无评论