Beginner with Jasmine, very first attempt with Jasmine Spies. I thought I was mimicking the format displayed here (search: "andReturn"), but I'm getting an error that I can't work out:
TypeError: Object function () { callTracker.track({ object: this, args: Array.prototype.slice.apply(arguments) }); return spyStrategy.exec.apply(this, arguments); } has no method 'andReturn'
No clue what I'm doing wrong. Here's my Spec:
describe('Die', function() { it('returns a value when you roll it', function() { var die = Object.create(Die); spyOn(Math, 'random').andReturn(1); expect(die.roll()).toEqual(6); }); });
And the corresponding JS:
var Die = { roll: function() { return Math.floor(Math.random() * 5 + 1); } }
Thanks for the help!!!
jasmine 2.0 changed some of the spy syntax. jasmine 2.0 docs
spyOn(Math, 'random').and.returnValue(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With