我有一个函数,我想弄乱它的输出。这有点像 andCallThrough 和 andCallFake 的组合。例如,假设我有这个构造函数:
function Widget() {
this.frobble = function() {return 1;};
}
function frotz() {
return new Widget().frobble();
}
我想要做的是这样的:
describe("Widget", function() {
it("is created and frobbled when frotz() is called", function() {
var widget;
spyOn(window, 'Widget').andMessWithOutput(function(newWidget) {
widget = newWidget;
spyOn(widget, 'frobble').andCallThrough();
frotz();
expect(widget.frobble.calls.length).toBe(1);
});
});
});