-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rejectedWith not checking the error message #272
Comments
Having the same issue here. Code to replicate: it('test', async () => {
function reject42() {
return Promise.reject(42);
}
await expect(reject42()).to.be.rejectedWith(999);
}); it('test', async () => {
function reject42() {
return Promise.reject(42);
}
await expect(reject42()).to.be.eventually.rejectedWith(999);
}); In both cases test passes rather than fail. |
A bit late but I guess this library looks for actual thrown errors for rejected values, for example this fails as expected it('test', async () => {
function reject42 () {
return Promise.reject(new Error('42'))
}
await expect(reject42()).to.eventually.be.rejectedWith('999')
}) |
@masterpandabear But this is only true, if no rejected value is part of the error. Here are some false-positive example: const mocha = require("mocha");
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
it('test 1', async () => {
function reject42() {
return Promise.reject(new Error('42'))
}
await chai.expect(reject42()).to.eventually.be.rejectedWith('4')
});
it('test 2', async () => {
function reject42() {
return Promise.reject(new Error('42'))
}
await chai.expect(reject42()).to.eventually.be.rejectedWith('2')
}); Both tests are passing, which is not expected (for me), because it's obvious that Reproducible source code: https://github.com/nilsreichardt/playground/blob/chai-as-promised-error-message-bug/test/index_test.js |
rejectedWith is not returning error when if error message is different from actual value.
Node version: 10.16.3
chai-as-promised version: 7.1.1
chai version: 4.2.0
E.g.: expect(fn()).to.be.rejectedWith(CustomError, error message) is returning always true as long as fn is just throwing custom Error with an error message whose prefix is same as error message.
The text was updated successfully, but these errors were encountered: