Menu

#3 Cannot make stub for method `find` in Firefox 25

open
dewindj
None
5
2013-12-03
2013-12-03
No

Firefox 25 throws error when trying to make stub for method find as in example

mock.expects().find().andStub(function() { return "returnValue" });

Error message is: "TypeError: this.__lastMock.calls[this.__lastCallName].push is not a function".

this.__lastMock.calls is an array, which already has in Firefox method with name find (and a lot of other functions), and because of this JSMock does not initialize property find with an empty array before calling push on it.

In fact, JSMock will throw error when creating stub for any method which name is in Array.prototype, e.g.

  • join
  • reverse
  • concat
  • find (currently only in Firefox 25+)
  • shift
  • unshift
  • etc.

In order to fix most of the problems property calls should be declared as object, not an array:

var mock = { calls: {}, expects: function() {this.__recording = true; return this}, __recording: false};

__initializeReturnExpectationForMock() should be also improved.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.