mocha/chai: assert thrown error

You want to test a function which trhwos an error. But you can not catch that function inside the chai assertions.

One way to fix this is to wrap your function inside an anonymous function.

class SystemUnderTest {

    run() {
        throw new Error('I always puke!');

module.exports = SystemUnderTest;

const SUT = require('../../utils/test.js'); ... it('catching thrown errors', () => { let sut = new SUT(); // expect(; // FAILS expect(() =>; // PASS });

You may also like...