Assertion Library for Browsers and NodeJS
Based on the API Interface of the NodeJS Assert module. And is part of the uTest Library.
As a standalone module can be found in NPM repository
npm install assertion
API
NodeJS API
-
assertequalnotEqualdeepEqualnotDeepEqualstrictEqualnotStrictEqualthrowsdoesNotThrowifError
Additional API
-
has / hasNot
Subset matching
// Substring searchassertWhen checking arrays or objects, deep matching is performed. See tests
assert; -
is/isNot
Type check
// Check by TypenameassertTypename is extracted from
Object.prototype.toString.call
, so these are:'String''Number''Null''Undefined''Function''RegExp''Date''Object' // any `object` will pass here'HTML**' // DOM Node, e.g. HTMLBodyElement'CustomEvent'...all other built-in types -
lessThan
lessThanOrEqaul
greaterThan
greaterThanOrEqual
Compares two digits
-
Aliases
There are also aliases (which can be set to globals, to simplify the write-read of tests)
asserteq_ === assertequalassertnotEq_ === assertnotEqualassertlt_ === assertlessThanassertlte_ === assertlessThanOrEqaulassertgt_ === assertgreaterThanassertgt_ === assertgreaterThanOrEqualassertdeepEq_ === assertdeepEqualassertnotDeepEq_ === assertnotDeepEqual -
jQuery
jQuery Assertion Extensions (alias name syntax)
$fneq_$fnnotEq_$fndeepEq_$fnnotDeepEq_$fnhas_$fnhasNot_$fnlt_$fnlte_$fngt_$fngte_Functions API:
- Get Property
(Key, Expected)
([Key, Expected], message)
- Function call
(FnName [, ...arguments], Expected)
([FnName [, ...arguments], Expected], message)
has/hasNot
- Node Find/Filter Assertions
(Selector, ?ExpectedCount)
Example:
// <div class='container' id='foo'>// <h4>Baz</h4>// <span>Qux</span>// </div>// addition sample;; - Get Property
-
Assert callbacks calls
-
await
Wait for a callback
Creates a wrapper function to ensure that the function is called.
// ! Arguments order does not mattervar fn = assert;// creates item in assert.callbacksname: Stringerror: Error // to receive the stack tracecount: Number;// after the `fn` function is called `count` times, then the object is removed// from the callbacks set// Examplevar fn = assert;assertcallbackslength === 1;trythrowcatch;assertcallbackslength === 0; -
avoid
Unexpect more then N function calls
// ! Arguments order does not mattervar fn = assert;
-
-
Listener
You can attach listener to the assertions. Event Types:
start
fail
if
fail
type listener is attached, then exceptions are not thrown.success
// sampleassert;
©️ MIT - The Atma.js Project