Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jasmine's `andReturn` vs `andCallFake`
// Jasmine's `andReturn` sets the value at instantiation and it can
// never be changed after that apparently. Use `andCallFake` instead
// if you need it to be dynamic.
var value = 9;
var getValueOne = jasmine.createSpy('spyOneAndReturn').andReturn(value);
var getValueTwo = jasmine.createSpy('spyOneCallFake').andCallFake(function () {
return value;
var setValue = jasmine.createSpy('spyTwo').andCallFake(function (newValue) {
value = newValue;
getValueOne(); // 9
getValueTwo(); // 9
getValueOne(); // still returns 9
getValueTwo(); // returns 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.