I want to mock test data in my Jasmine tests. Here are two versions:
// version 1: spyOn(mBankAccountResource, 'getBankAccountData').and.callFake(fakedFunction); // version 2: spyOn(mBankAccountResource, 'getBankAccountData').andCallFake(fakedFunction);
When I execute my tests with a browser (Chrome, Firefox) then the first version works. However, when I run the same test with phantomjs, I have to use the second version. Otherwise, it complains that the function is not defined.
Here are the error messages:
// phantomjs (with version 1) TypeError: 'undefined' is not an object (evaluating 'spyOn(mBankAccountResource, 'getBankAccountData').and.callFake') at /home/phil/workspaces/world/basket.angular.ui/basket.angular.ui/test/bankaccount/BankAccountCtrlTest.js:65 at invoke (/home/phil/workspaces/world/basket.angular.ui/bower_components/angular/angular.js:3707) at workFn (/home/phil/workspaces/world/basket.angular.ui/bower_components/angular-mocks/angular-mocks.js:2149) undefined // Chrome (with version 2) TypeError: Object function () { callTracker.track({ object: this, args: Array.prototype.slice.apply(arguments) }); return spyStrategy.exec.apply(this, arguments); } has no method 'andCallFake' at Object. (/home/phil/workspaces/world/basket.angular.ui/basket.angular.ui/test/bankaccount/BankAccountCtrlTest.js:65:59) at Object.invoke (/home/phil/workspaces/world/basket.angular.ui/bower_components/angular/angular.js:3707:17) at Object.workFn (/home/phil/workspaces/world/basket.angular.ui/bower_components/angular-mocks/angular-mocks.js:2149:20)
I searched the Jasmine API but could not find out which version is the correct one. All examples that I found seem to use the second version.
Did the API of Jasmine change recently? How can I write my tests, so it always works?