assert-helpers
- Version 11.12.0
- Published
- 151 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
function color
color: (value: any, color: Function) => string;
Applies the color to the value if desired
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.
function contains
contains: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Checks to see if the actual result contains the expected result .
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
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
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
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.
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.
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.
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.
function gt
gt: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is greater than
function gte
gte: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is greater than or equal to
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
function isNode
isNode: () => boolean;
Whether or not we are running in the node environment
function isTTY
isTTY: () => boolean;
Whether or not stdout and stderr are interactive.
function log
log: (...args: any) => void;
Log the inspected values of each of the arguments to stdout
function logComparison
logComparison: (actual: any, expected: any, error: Error | string | any) => void;
Output a comparison of the failed result to stderr
function lt
lt: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is less than
function lte
lte: ( actual: any, expected: any, testName?: string, next?: Errback) => void | never;
Is less than or equal to
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 .
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
function returnErrorViaCallback
returnErrorViaCallback: (error?: Error | string) => () => Error;
Generate a callback that return an error instance with the specified message/error.
function returnViaCallback
returnViaCallback: (value: any) => () => typeof value;
Generate a callback that will return the specified value.
function throwErrorViaCallback
throwErrorViaCallback: (error?: Error | string) => () => never;
Generate a callback that throw an error instance with the specified message/error.
function undef
undef: (actual: any, testName?: string, next?: Errback) => void;
Ensure what is passed is undefined, otherwise fail and output what it is
function useColors
useColors: () => boolean;
Whether or not colors are desired on this environment
function wait
wait: (delay: number, fn: (...args: any[]) => void) => NodeJS.Timeout;
Alias for setTimeout with paramaters reversed.
Package Files (1)
Dependencies (3)
Dev Dependencies (16)
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[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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 1453 ms. - Missing or incorrect documentation? Open an issue for this package.