ist
This is a tiny assertion library (in the same space as
require("assert")
) that is only a handful of lines, and exports a
simple API.
var ist = require("ist")
ist([] instanceof Array)
ist(1 + 1, 2)
ist(1 + 1, 3, "<")
ist(a, b, myCompareFunc)
ist.throws(function() { undefined.prop })
ist
(value)
Throws a exception of class ist.Failure
when value
is falsy.
ist
(a, b, compare)
Compares a
and b
, and throws an ist.Failure
if the comparison
fails. compare
defaults to ==
, but you can pass a string that
corresponds to a JavaScript comparison operator, or a custom function,
to compare in a different way.
ist.throws
(f, matches)
Ensure that calling f
throws an exception, and optionally test
whether the exception matches your expectation. matches
may be a
regexp, which is matched against the exception's message
property, a
string, which should be the same as the message
, or a function that
takes an exception and returns a boolean.
License
This software is licensed under an MIT license.