我有一个 Jasmine 测试失败,因为正在生成一个随机数,并且这个随机值对于执行和规范是不同的。
fetch: function(options) {
if(typeof options === "undefined") {
options = {};
}
if(typeof options.data === "undefined") {
options.data = {};
}
options.data.id = this.journalId;
options.data.random = Math.floor(Math.random()*10000);
col.prototype.fetch.call(this, options);
}
下面的测试失败,因为Math.floor(Math.random()*10000)
正在生成不同的值。
it("should call parent fetch with default options", function() {
this.collection.fetch();
expect(this.fetchSpy).toHaveBeenCalledWith({
data: {
id: 1,
random: Math.floor(Math.random()*10000)
}
});
});
对于生成随机数的情况,有没有办法让我的测试通过?