Lets say I want to write this simple task. But I want to write a test validating that:
- This task emits object.
- Object has a property name.
I'm testing with mocha and chai expect.
Thanks in advance. I've tried every possible variant that came to mind, but could not come up with a solution.
var util = require('util'),
EventEmitter = require('events').EventEmitter;
function SomeTask() {
var self = this;
setInterval(function() {
self.emit('data', { name: 'name' });
}, 5000);
}
util.inherits(SomeTask, EventEmitter);
module.exports = SomeTask;
Here's an example using spies. https://github.com/mochajs/mocha/wiki/Spies