npm install --save-dev stepperbox
StepperBox is a testing library for creating stub functions that invoke different callbacks at different steps. It works similarly to a Sinon spy, but is much simpler in its implementation and usage. This allows you to create much more explicit mock behavior without knowing any cryptic API.
var stepperbox = require('stepperbox');
var stepper = stepperbox();
stepper.add(function (input) {
console.log('step 1', input);
});
stepper.add(function (input) {
console.log('step 2', input);
});
stepper(5);
stepper(6);
// Outputs:
// "Step 1", 5
// "Step 2", 6This can be further extended for testing by using Function.prototype.bind to create curried versions of the stepper for mocking multiple pieces. The below example shows how you could use stepper with proxyquire to mock a mysql.query dependency.
var mymodule = proxyquire('path/to/mymodule', {
mysql: {
query: stepper.bind('mysql.query');
}
});
stepper.add(function (calledas, query, data) {
assert.equal(calledas, 'mysql.query');
assert.equal(query, 'SELECT NOW()');
assert.deepEqual(data, []);
});Returns a stepper instance, a chainable class for defining the callbacks for each step. An array of callbacks may be provided to be used as the initial steps.
Appends a callback step to the end of the current chain
Inserts a callback step at the specified index (0 based) in the sequence.
Syntactic sugar for onCall. Inserts a callback step at the first, second or third positions, respectively.
Resets the stepper position to the first step.
Resets the stepper position, and removes all existing steps.
Resets the stepper position, and overwrites all existing steps with the callbacks provided in the array.