【发布时间】:2015-03-16 12:34:27
【问题描述】:
我一直在阅读 Jasmine 文档,并且一直在努力理解 Spies .and.stub 方法的实际作用。英语不是我的母语,所以我什至不知道“存根”这个词的真正含义,也没有我的语言的翻译。
在文档中它说:
当一个调用策略用于spy时,可以随时用and.stub返回原始的存根行为。
describe("A spy", function() {
var foo, bar = null;
beforeEach(function() {
foo = {
setBar: function(value) {
bar = value;
}
};
spyOn(foo, 'setBar').and.callThrough();
});
it("can call through and then stub in the same spec", function() {
foo.setBar(123);
expect(bar).toEqual(123);
foo.setBar.and.stub();
bar = null;
foo.setBar(123);
expect(bar).toBe(null);
});
});
and.stub 的实际作用是什么?它有什么用处?
【问题讨论】:
标签: javascript unit-testing jasmine