Jasmine 初学者, Jasmine spy 的第一次尝试。我以为我在模仿格式 displayed here (搜索:“andReturn”),但我收到一个无法解决的错误:
TypeError: Object function () {
callTracker.track({
object: this,
args: Array.prototype.slice.apply(arguments)
});
return spyStrategy.exec.apply(this, arguments);
} has no method 'andReturn'
不知道我做错了什么。这是我的规范:
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);
});
});
以及对应的JS:
var Die =
{
roll: function() {
return Math.floor(Math.random() * 5 + 1);
}
}
感谢您的帮助!!!
最佳答案
jasmine 2.0 更改了一些 spy 语法。 jasmine 2.0 docs
spyOn(Math, 'random').and.returnValue(1);
关于javascript - Jasmine对象 “has no method '并返回'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21590005/