Run tests against incoming data.
$ npm install datatester// require dataTester module
var dataTester = require('datatester');
// Create new Instance
var tester = new dataTester();
// Add test
tester.addTest('string', function(data) {
return typeof data == 'string';
});
// Register listener for results
tester.on('result', function(result) {
console.log('Passed tests: ' + result.tests);
console.log('Data: ' + result.data);
});
// send some sample data
tester.emit('data', 'randomMessage');
tester.emit('data', 12345);
tester.emit('data', 'randomMessage');
tester.emit('data', {});
tester.emit('data', 'randomMessage');
tester.emit('data', []);
// you should see the listener was called 6 timesAlias for setTest.
The setTest method accepts a name string and test function and stores the test function under the specified name.
The test function has to return true or false.
The getTest method accepts a name string and returns the test stored under the specified name.
The delTest method accepts a name string and deletes the test stored under the specified name.
The data event is used to send the tester a new data entry with the data parameter containing the data.
The result event is fired when the tests are finished. It returns a result containing a tests array that contains all passed tests and a data field containing the data.
MIT