Tengo una función que espero que arroje un error, pero si no lo arroja, Mocha pasa la prueba.
async function throwError() { throw new Error("foo"); } async function notThrowError() { }Prueba:
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 }) }Debería usar 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 }) }