anna rivis
anna rivis

Reputation: 13

chai-as-promised's eventually passes wrong rejection

suddenly I realized that in many of my tests it wrongly passes the fail test, I tried to understand the reason, here's is an example that passes the test which is wrong

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

can anyone help me to figure out what am doing wrong? thanks

Upvotes: 1

Views: 88

Answers (1)

Robot
Robot

Reputation: 991

to.not.eventually is not the same as to.eventually.not

You’re using not, it should be before the eventually So change your test to below code to use to.not.eventually to see it won’t get passed and it’ll fail

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;
  });
});

Upvotes: 1

Related Questions