【发布时间】:2016-09-20 13:58:35
【问题描述】:
我正在尝试编写一个测试,我需要根据是第一次调用还是第二次调用不同的函数来存根函数。到目前为止,我已经尝试过:
this.dispatcherStub = sinon.stub(alt.dispatcher, 'dispatch');
this.dispatcherStub.onFirstCall().returns((dataArgs) => {
// Some assertion on the data
});
this.dispatcherStub.onSecondCall().returns((dataArgs) => {
// Another assertion on the data
done();
});
请注意,我需要它们是不同的函数,而不仅仅是返回不同的值,因为我需要在第二个函数中调用 mocha 的 done(),因为它是异步调用的。
【问题讨论】:
标签: javascript mocha.js sinon