cloudhead/vows — pull request #212 by Filirom1 (2012-04-21 14:16:39+00:00)
Title: Expect a vow to be called n times

When testing events, it's quite common that a vow is executed multiple times.
This job is done in the pull request #193 by @bacchusrx

But it's also quite common to test how many times the vow was called.

I added the function `expect(num)` in the vow context.

vows.describe("Vows with events that fire mutiple times").addBatch({
"A context": {
topic: function() {
this.context.event = 'end';

var topic = new(events.EventEmitter);

process.nextTick(function () {
topic.emit('ping', 'ping_data');
topic.emit('ping', 'ping_data');
});

process.nextTick(function() {
topic.emit('end', 'end_data');
});

return topic;
},
on: {
"ping": {
"will fire with ping_data": function(data) {
this.expect(7);
assert.strictEqual(data, 'ping_data');
}
},
"end": {
"will fire will end_data": function(data) {
assert.strictEqual(data, 'end_data');
}
}
}
}
}).export(module);

✗ Errored » Expected to be called 7 time(s) but was 2
in A context on ping will fire with ping_data
in Vows with events that fire mutiple times
in test/vows-test.js