1.0.1 • Published 5 years ago
assert-chain v1.0.1
Assert Chain
A chainable assertion interface for Node.
This module contains a chainable version of the riteway assertion library, and the native one. This library can be considered stable, as it does have tests included.
API
The API is quite simple. Two functional classes are exported.
var chain = require('assert-chain');
var ritewayChain = new chain.RitewayChain(/* assertModule = require('riteway') */);
var assertChain = new chain.AssertChain(/* assertModule = require('assert') */);
ritewayChain
.given('no arguments')
.should('return 0')
.actual(sum())
.expected(0);
// You can access the state of a chain:
ritewayChain.__given__ === 'no arguments';
ritewayChain.__should__ === 'return 0';
ritewayChain.__actual__ === sum();
ritewayChain.__expected__ === 0;
// Chains auto-fire when all methods have been called.
// The condition() call can be changed to assertion() or cond() too.
assertChain
.message('expected "value" to be a function')
.condition(2);
// Or you can provide the message *with* the assertion.
var newAssertChain = new chain.AssertChain();
newAssertChain
.condition(2, 'expected "value" to be a function');
// You can access the state of assertion chains, too:
newAssertChain.__assertion__ === 2;
newAssertChain.__message__ === 'expected "value" to be a function';
// You can also call the classes as functions, à la functional classes.
chain.AssertChain();
chain.RitewayChain();
Issues and Features
If you wish to contribute anything to this project, submit a Pull Request or an Issue.