柴如承诺最终通过错误的拒绝



我突然意识到,在我的许多测试中,它错误地通过了失败测试,我试图理解原因,这里有一个通过测试的例子,它是错误的

describe('...', () => {
it('...', () => {
return chai.expect(Promise.reject('boom')).to.eventually.not.rejected;
});
});

有人能帮我弄清楚哪里做错了吗?感谢

to.not.eventuallyto.eventually.not不同

您正在使用not,它应该在最终之前,所以将您的测试更改为以下代码以使用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;
});
});

最新更新