Jasmine Spy Undefined

John picture John · Aug 19, 2012 · Viewed 9k times · Source

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.

Answer

Chris Salzberg picture Chris Salzberg · Aug 19, 2012

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

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