I have a function that I expect to throw an error, but if it doesn't throw it mocha passes the test.
async function throwError() {
throw new Error("foo");
}
async function notThrowError() {
}
Test:
describe("bar", function(){
it("bar-2", async function() {
await expect(throwError()).throw //passes the test
})
}
describe("bar", function(){
it("bar-2", async function() {
await expect(notThrowError()).throw //passes the test, but no error has been thrown
})
}
I should use chai as promised
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
describe("bar", function(){
it("bar-2", async function() {
return notThrowError().should.eventually.rejected; //do not pass the test if not throw an error
})
}