【发布时间】:2017-10-13 14:28:30
【问题描述】:
我有一些在 promise 解决后执行的代码。我正在尝试监视一个应该在承诺后解决方案中调用的方法,但是在调用对监视的方法的调用之前,我的测试完成执行时遇到问题。
我如何测试对storage.add 的调用实际上是在进行的?
这是测试:
"it marks true in storage": function() {
sinonSandbox.stub(tested, "updateServiceApi", function() {
return MPromise.resolve();
});
var storageStub = sinonSandbox.stub(storage, "add");
tested._execute();
expect(
storageStub.calledWith("name", true)
).to.be.true
}
下面是实现:
_execute: function() {
this.updateServiceApi().then(function(){
// tests finish before this code is executed :(
storage.add("name", true);
});
},
【问题讨论】:
-
你用的是什么测试运行器?
标签: javascript promise mocking sinon spy