I use mocha, chai and promised chai. The test should fail but doesn't, I don't know what's going wrong, any suggestions?
const { describe, it } = require('mocha') const chai = require('chai') const { expect } = require('chai') const chaiAsPromised = require('chai-as-promised') chai.use(chaiAsPromised) describe('test', () => { it('must be rejected', async () => { expect(Promise.resolve('success')).to.rejected }) })
I'm trying to test a promise that should be rejected, the test should fail, but the test succeeds
Excerpted fromChai as Promised document
You can use
async /await
or.then(() => {})
to include multiple Promises in your test.These four tests will fail:
Example:https://stackblitz.com/edit/node- a7t3tx?file=index.js