1.5.1 • Published 9 years ago
expressive-assertion v1.5.1
expressive-assertion
Expressive assertions for JavaScript.
Getting Started
Installation
npm install expressive-assertion --save
Integration
var assert = require('expressive-assertion');
API
assert(predicate, ...)
assert(function () {
return true;
}); // OK
assert(function () {
return false;
}); // AssertionError: assert(function () { return false; })
assert(function () {
return true;
}, function () {
return true;
}); // OK
assert(function () {
return true;
}, function () {
return false;
}); // AssertionError: assert(function () { return false; })
assert.throws(block, predicate, ...)
assert.throws(function () {
throw 'foo';
}); // OK
assert.throws(function () {
return 'foo';
}); // AssertionError: Missing expected exception.
assert.throws(function () {
throw 'foo';
}, function (exception) {
return exception === 'foo';
}); // OK
assert.throws(function () {
throw 'foo';
}, function (exception) {
return exception !== 'foo';
}); // AssertionError: assert(function (exception) { return exception !== 'foo'; })
assert.throws(function () {
return 'foo';
}, function (exception) {
return exception === 'foo';
}); // AssertionError: Missing expected exception.
assert.throws(function () {
throw 'foo';
}, function (exception) {
return exception === 'foo';
}, function (exception) {
return exception !== 'bar';
}); // OK
assert.throws(function () {
throw 'foo';
}, function (exception) {
return exception === 'foo';
}, function (exception) {
return exception !== 'foo';
}); // AssertionError: assert(function (exception) { return exception !== 'foo'; })
assert.throws(function () {
return 'foo';
}, function (exception) {
return exception === 'foo';
}, function (exception) {
return exception !== 'bar';
}); // AssertionError: Missing expected exception.
Running Tests
To run the test suite first install the development dependencies:
npm install
then run the tests:
npm test