【发布时间】:2021-12-18 08:10:33
【问题描述】:
我下面的测试用例通过但我的断言失败。为什么会过去?我已经有了异步,甚至没有调用 updateSpy,我的 Assertion failed 消息证实了这一点。我也尝试过用承诺完成。
it('should call the update method once', async () => {
const updateSpy = sinon.spy(() => 'Spy!');
sinon.stub(service, 'db').resolves({
collection(collectionName) {
return {
update: updateSpy,
};
},
});
console.assert(updateSpy.called); // assertion failed but the test case was passed
});
【问题讨论】:
-
因为你是
console.assert。这只是将断言的结果记录到控制台。您需要使用一个会抛出错误的断言库,以便 Mocha 知道断言失败。
标签: javascript unit-testing mocha.js sinon