【发布时间】:2018-01-08 08:47:57
【问题描述】:
我用mocha+chai+sinon来测试函数,但是在promise中使用called属性,即使写了一个未定义的函数,called总是true,这是什么原因造成的?以及如何解决?thx
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();
});
【问题讨论】:
标签: javascript testing mocha.js sinon