UNPKG

assertthat

Version:
43 lines (42 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertFunctionIsNotThrowing = void 0; const errors_1 = require("../../errors"); const defekt_1 = require("defekt"); const assertFunctionIsNotThrowing = function (actual, expected) { try { actual(); // eslint-disable-next-line @typescript-eslint/no-implicit-any-catch } catch (ex) { if (expected === undefined) { return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The function threw an unexpected exception.', actual: `Error message:\n${ex.message}` })); } if (expected instanceof RegExp && expected.test(ex.message)) { return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The function threw an unexpected exception.', expected: `The message should not have matched:\n${expected.toString()}`, actual: `Error message:\n${ex.message}` })); } if (typeof expected === 'function' && expected(ex)) { return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The function threw an unexpected exception.', expected: `The exception should not have fulfilled a predicate.`, actual: `Error message:\n${ex.message}` })); } if (typeof expected === 'string' && ex.message === expected) { return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The function threw an unexpected exception.', expected: `The message should not have been:\n${expected}`, actual: `Error message:\n${ex.message}` })); } } return (0, defekt_1.value)(); }; exports.assertFunctionIsNotThrowing = assertFunctionIsNotThrowing;