UNPKG

@zoroaster/assert

Version:

The Assertion Library For Zoroaster Context Testing Framework Including Deep Equal & Assert Throws.

66 lines (61 loc) 3 kB
const { _throws, _deepEqual } = require('./assert') const assert = require('assert') const { equal, ok } = assert /** * Assert that a function throws and check the thrown error properties. ```js await throws({ fn: method, args: ['test', true], message: /An error occurred:/, // regex code: 'ENOTEST', // string stack(stack) { // function equal(stack.length, 2) } }) ``` * @param {_assertThrows.Config} config Parameters to the `assert-throws` method. * @param {!Function} config.fn The function to test, either sync or async. * @param {*|!Array<*>} [config.args] The arguments or single argument to pass to the function. * @param {*} [config.context] The context in which to execute the function. Global context will be set by default. * @param {_assertThrows.Assertion} [config.message] A string, regex, or function to test the message. * @param {_assertThrows.Assertion} [config.code] A string, regex, or function to test the code. * @param {_assertThrows.Assertion} [config.stack] A string, regex, or function to test the stack. * @param {_assertThrows.Assertion} [config.prop] A string, regex, or function to test any other property of the error. * @param {Error} [config.error] An error to perform strict comparison against. * @return {Promise} */ function throws(config) { return _throws(config) } /** * Calls `assert.deepStrictEqual` and then creates a visual representation of the difference between objects if it throws. * @param {?} actual The actual value. * @param {?} expected The expected value. * @param {string=} [message] The message with which to fail if the assertion didn't succeed. */ function deepEqual(actual, expected, message) { return _deepEqual(actual, expected, message) } module.exports = { deepEqual, throws, assert, equal, ok, } /* typal node_modules/@zoroaster/assert-throws/types/index.xml namespace */ /** * @typedef {_assertThrows.Assertion} Assertion An assertion to perform. * @typedef {!(string|RegExp|!Function)} _assertThrows.Assertion An assertion to perform. * @typedef {_assertThrows.Config} Config Parameters to the `assert-throws` method. * @typedef {Object} _assertThrows.Config Parameters to the `assert-throws` method. * @prop {!Function} fn The function to test, either sync or async. * @prop {*|!Array<*>} [args] The arguments or single argument to pass to the function. * @prop {*} [context] The context in which to execute the function. Global context will be set by default. * @prop {_assertThrows.Assertion} [message] A string, regex, or function to test the message. * @prop {_assertThrows.Assertion} [code] A string, regex, or function to test the code. * @prop {_assertThrows.Assertion} [stack] A string, regex, or function to test the stack. * @prop {_assertThrows.Assertion} [prop] A string, regex, or function to test any other property of the error. * @prop {Error} [error] An error to perform strict comparison against. */