谁能告诉我为什么以下测试失败。
var Person = function() {};
Person.prototype.helloSomeone = function(toGreet) {
return this.sayHello() + " " + toGreet;
};
Person.prototype.sayHello = function() {
return "Hello";
};
describe("Person", function() {
it("calls the sayHello() function", function() {
var fakePerson = new Person();
spyOn(fakePerson, "sayHello");
fakePerson.helloSomeone("world");
expect(fakePerson.sayHello).toHaveBeenCalled();
});
});
我从 here 拿来的他说这行得通。我可以看到 spyOn 方法在 person 对象上创建了一个同名的包装函数,即 fakePerson.sayHello 是在对象而不是原型(prototype)上调用的。
非常感谢
最佳答案
测试失败,因为我还使用了 jasmine-sinon.js。
关于javascript - Jasmine 的 spyOn toHaveBeenCalled 方法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9396538/