【问题标题】:chai-as-promised's eventually passes wrong rejectionchai-as-promised 最终通过了错误的拒绝
【发布时间】:2021-07-24 02:50:27
【问题描述】:
突然我意识到在我的许多测试中它错误地通过了失败测试,我试图理解原因,这是一个通过测试的示例,这是错误的
describe('...', () => {
it('...', () => {
return chai.expect(Promise.reject('boom')).to.eventually.not.rejected;
});
});
谁能帮我弄清楚做错了什么?谢谢
【问题讨论】:
标签:
node.js
unit-testing
testing
mocha.js
chai
【解决方案1】:
to.not.eventually与to.eventually.not不一样
你用的不是,应该在finally之前
因此,将您的测试更改为下面的代码以使用to.not.eventually 来查看它不会通过并且会失败
const { describe, it } = require('mocha');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { expect } = chai;
describe('...', () => {
it('...', () => {
return expect(Promise.reject(new Error('boom'))).to.not.eventually.rejected;
});
});