cloudhead/vows — Issue #191: Testing multiple events
Author: bacchusrx
Created: 2012-02-12 19:51:01+00:00
State: open

I've run into a similar problem, except when firing multiple events rather than multiple callbacks. I'm posting about it here because of your comment in #79, @indexzero, that this should be supported. I'd like to know whether the behaviour I'm seeing is expected, a bug, or if I'm going about it the wrong way.

Basically I'm doing some testing of hook.io hooks, using the new event support from #109/#145, and in some cases I'm testing events that need to fire multiple times, and I have to verify they fired the correct number of times. So, I use a macro to generate a vow for the event that closes over a counter which is incremented each time the vow fires, and another vow that later on checks the counter. So far so good.

What happens is that the `batch.honored` counter is incremented each time a duplicate event is fired successfully, and so sometimes in `tryEnd` (in `lib/vows/suite.js`) this condition fails:

```javascript
if (batch.honored + batch.broken + batch.errored + batch.pending === batch.total &&
batch.remaining === 0) {
```

because there were more vows honored than in `batch.total` (which is incremented when `addVow` is called).

The result is that the batch hangs indefinitely.

I was able to work around this by changing the conditional from `===` to `>=` and moving the tally,

```javascript
Object.keys(batch).forEach(function (k) {
(k in batch.suite.results) && (batch.suite.results[k] += batch[k]);
});
```

down into `finish()`. This didn't break my own tests or the Vows tests, but, I'm not sure what other implications it might have.

If this behaviour (testing multiple events) should work I can put together a failing test, but I'd like to know if I've encountered a bug, or if this is expected and there's another way to do this.