这里的问题是
.catch
块正在捕获
.then
块
这是一个问题,因为您正在呼叫
done
未通过
err
对象摩卡将此解释为测试正确通过,而不是失败。
修复程序:
describe("when click get verifycode", function () {
it('if get server response success, should start countdown', function (done) {
// given
sandbox.stub(model, 'getVerifyCode').resolves({});
sandbox.spy(view, 'startCountDown');
// when
var result = instance.onClickVerify('123456');
// then
result.then(res => {
// no matter what function, called always true
// e.g. expect(AnUndefinedFunction.called).to.be.ok;
expect(instance.view.startCountDown.called).to.be.ok;
done();
}).catch(err => {
done(err);
});
})
});