Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine object “has no method 'andReturn'”

Tags:

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!!!

like image 496
i_made_that Avatar asked Feb 05 '14 22:02

i_made_that


1 Answers

jasmine 2.0 changed some of the spy syntax. jasmine 2.0 docs

spyOn(Math, 'random').and.returnValue(1); 
like image 177
Gregg Avatar answered Dec 31 '22 21:12

Gregg