chai-as-promised 最终通过了错误的拒绝

chai-as-promised's eventually passes wrong rejection

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

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

谁能帮我弄清楚哪里做错了?谢谢

to.not.eventuallyto.eventually.not

不同

你用的不是,应该是eventually之前 因此,将您的测试更改为以下代码以使用 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;
  });
});