Skip to content

Actually fail tests when function in question does not throw error as expected

Eric Eastwood requested to merge 2790-fix-thrown-error-assertion-fail into develop

Actually fail tests when function in question does not throw error as expected

Fix #2790 (closed)

Added TestError which we can throw whenever we do the assert.fail(new TestError('...')); and then know it's the only special error we need to re-throw to fail the test.

const TestError = require('gitter-web-test-utils/lib/test-error');

try {
  someFunction();
  assert.fail(new TestError('expected error to be thrown'));
} catch (err) {
  if (err instanceof TestError) {
    throw err;
  }

  assert.ok(err);
}

Dev notes

Places of interest

  • assert(err
  • assert.ok(err
  • assert.ok(false
  • assert.fail(

Affected tests

Edited by Eric Eastwood

Merge request reports