1.0.11 • Published 7 years ago
@kingjs/assert v1.0.11
@kingjs/assert
Throw an exception if a condition fails.
Usage
Assert a condition in your code or test like this:
var assert = require('@kingjs/assert');
assert(0 == 1);throws:
"An assertion failed."Simply fail all the time like this:
var assert = require('@kingjs/assert');
assert();throws:
"An assertion failed."Provide a more descriptive error message like this:
var assert = require('@kingjs/assert');
var expected = 0;
var actual = 1;
assert(
actual == expected,
"Expected '" + expected + "' but actually got '" + actual + "'."
);throws:
"Expected '0' but actually got '1'."API
declare function assert(condition?: boolean, message?: string);Parameters
condition: If false (or omitted), throws an exception.
message: Message to throw if condition fails, else will throw "An assertion failed.".
Install
With npm installed, run
$ npm install @kingjs/assertAcknowledgments
assert is old as dirt and just as underappreciated.
License
MIT