chai.assert.isRejected Message validator not working

1.2k Views Asked by At

I'm attempting to write the following test:

return chai.assert.isRejected(quote.validate(), 'Amount is not valid number');

When running this test, it is successful but upon fudging it to ensure it fails with the following, it still passes:

return chai.assert.isRejected(quote.validate(), '123Amount is not valid number');

I also tried the following:

return chai.assert.isRejected(quote.validate(), new Error('Amount is not valid number'));

But it seems to fail:

AssertionError: expected promise to be rejected with [Error: Amount is not valid number] but it was rejected with [Error: Amount is not valid number]

I have reason to believe its failing though because they are referencing different Error instances but not 100% sure.

Ideally I would like to be able to ensure that the proper error / message is being returned but I can't seem to figure it out and was looking for some help.

** Note I am using chai-as-promised as well

1

There are 1 best solutions below

0
On

Perhaps try using expect instead of assert? I ran into the same issue when trying to use assert.

expect(promise).to.be.rejectedWith('Error msg.').and.notify(done)