assert-helpers
- Version 11.13.0
- Published
- 194 kB
- 3 dependencies
- Artistic-2.0 license
Install
npm i assert-helpers
yarn add assert-helpers
pnpm add assert-helpers
Overview
Common utilities and helpers to make testing assertions easier
Index
Functions
- bool()
- color()
- completeViaCallback()
- contains()
- deepEqual()
- equal()
- errorEqual()
- errorViaCallback()
- expectErrorViaCallback()
- expectErrorViaFunction()
- expectFunctionToThrow()
- expectThrowViaFunction()
- expectViaCallback()
- gt()
- gte()
- inspect()
- isNode()
- isTTY()
- log()
- logComparison()
- lt()
- lte()
- notContains()
- nullish()
- returnErrorViaCallback()
- returnViaCallback()
- throwErrorViaCallback()
- undef()
- useColors()
- wait()
Functions
function bool
bool: (value: any) => boolean | null;
Convert a value to its boolean equivalent
Parameter value
The value to convert to boolean
Returns
The boolean equivalent of the value, or null if undetermined
function color
color: (value: any, color: (input: any) => string) => string;
Applies the color to the value if desired
Parameter value
The value to colorize
Parameter color
The color function to apply
Returns
The colorized string if colors are enabled, otherwise the string value
function completeViaCallback
completeViaCallback: ( value: any, delay?: number) => (complete: (error: null, result: typeof value) => void) => void;
Generate a callback that will receive a completion callback whcih it will call with the specified result after the specified delay.
Parameter value
The value to pass to the completion callback
Parameter delay
The delay in milliseconds before calling the completion callback
Returns
A function that takes a completion callback and calls it with the value after the delay
function contains
contains: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Checks to see if the actual result contains the expected result .
Parameter actual
The actual value to check for containment
Parameter expected
The expected value that should be contained
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function deepEqual
deepEqual: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Same as assert.deepStrictEqual in that it performs a deep strict equals check, but if a failure occurs it will output detailed information
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function equal
equal: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Same as assert.strictEqual in that it performs a strict equals check, but if a failure occurs it will output detailed information
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function errorEqual
errorEqual: ( actualError: any, expectedError: any, testName?: string, next?: Errback) => void | never;
Checks to see if an error was as expected, if a failure occurs it will output detailed information
Parameter actualError
The actual error that was thrown
Parameter expectedError
The expected error to match against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function errorViaCallback
errorViaCallback: ( error: Error | string, delay?: number) => (complete: (error: Error | string) => void) => void;
Generate a callback that will receive a completion callback which it will call with the passed error after the specified delay.
Parameter error
The error to pass to the completion callback
Parameter delay
The delay in milliseconds before calling the completion callback
Returns
A function that takes a completion callback and calls it with the error after the delay
function expectErrorViaCallback
expectErrorViaCallback: ( expected: Error | string, testName?: string, next?: Errback) => (actual: Error | string) => void;
Generate a callback that will check its error (the actual error) against the passed error (the expected error). If a failure occurs it will output detailed information.
Parameter expected
The expected error to match against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
Returns
A function that compares an actual error with the expected error
function expectErrorViaFunction
expectErrorViaFunction: () => never;
Deprecated
Use expectErrorViaFunction instead
function expectFunctionToThrow
expectFunctionToThrow: () => never;
Deprecated
Use expectErrorViaFunction instead
function expectThrowViaFunction
expectThrowViaFunction: ( expected: Error | string, fn: () => never, testName?: string, next?: Errback) => void;
Expect the passed function to throw an error at some point.
Parameter expected
The expected error to match against
Parameter fn
The function that should throw an error
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function expectViaCallback
expectViaCallback: (...expected: any) => (...actual: any) => void;
Generate a callback that will check the arguments it received with the arguments specified, if a failure occurs it will output detailed information.
Parameter expected
The expected arguments to compare against
Returns
A function that compares received arguments with expected arguments
function gt
gt: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is greater than
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function gte
gte: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is greater than or equal to
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function inspect
inspect: (value: any, opts?: any) => string;
Return a stringified version of the value with indentation and colors where applicable. Colors will be applied if the environment supports it (--no-colors not present and TTY). For the available options, refer to https://nodejs.org/dist/latest-v14.x/docs/api/util.html#util_util_inspect_object_options for Node.js
Parameter value
The value to inspect and stringify
Parameter opts
Additional options for the inspection
Returns
The stringified and optionally colorized representation of the value
function isNode
isNode: () => boolean;
Whether or not we are running in the node environment
Returns
True if running in Node.js, false otherwise
function isTTY
isTTY: () => boolean;
Whether or not stdout and stderr are interactive.
Returns
True if both stdout and stderr are TTY, false otherwise
function log
log: (...args: any) => void;
Log the inspected values of each of the arguments to stdout
Parameter args
The values to log
function logComparison
logComparison: (actual: any, expected: any, error: Error | string | any) => void;
Output a comparison of the failed result to stderr
Parameter actual
The actual value that was received
Parameter expected
The expected value
Parameter error
The error that occurred during comparison
function lt
lt: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is less than
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function lte
lte: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is less than or equal to
Parameter actual
The actual value to compare
Parameter expected
The expected value to compare against
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function notContains
notContains: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Checks to see if the actual result does not contain the expected result .
Parameter actual
The actual value to check for non-containment
Parameter expected
The expected value that should not be contained
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function nullish
nullish: (actual: any, testName?: string, next?: Errback) => void;
Ensure what is passed is undefined or null, otherwise fail and output what it is
Parameter actual
The actual value to check
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function returnErrorViaCallback
returnErrorViaCallback: (error?: Error | string) => () => Error;
Generate a callback that return an error instance with the specified message/error.
Parameter error
The error message or Error instance to return
Returns
A function that returns an Error instance
function returnViaCallback
returnViaCallback: (value: any) => () => typeof value;
Generate a callback that will return the specified value.
Parameter value
The value to return from the callback
Returns
A function that returns the specified value
function throwErrorViaCallback
throwErrorViaCallback: (error?: Error | string) => () => never;
Generate a callback that throw an error instance with the specified message/error.
Parameter error
The error message or Error instance to throw
Returns
A function that throws an Error instance
function undef
undef: (actual: any, testName?: string, next?: Errback) => void;
Ensure what is passed is undefined, otherwise fail and output what it is
Parameter actual
The actual value to check
Parameter testName
The name of the test for error reporting
Parameter next
Optional callback to call with any error
function useColors
useColors: () => boolean;
Whether or not colors are desired on this environment
Returns
True if colors should be used, false otherwise
function wait
wait: (delay: number, fn: (...args: any[]) => void) => NodeJS.Timeout;
Alias for setTimeout with paramaters reversed.
Parameter delay
The delay in milliseconds before executing the function
Parameter fn
The function to execute after the delay
Returns
The timer ID returned by setTimeout
Package Files (1)
Dependencies (3)
Dev Dependencies (12)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/assert-helpers
.
- Markdown[](https://www.jsdocs.io/package/assert-helpers)
- HTML<a href="https://www.jsdocs.io/package/assert-helpers"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3702 ms. - Missing or incorrect documentation? Open an issue for this package.