Expect a vow to be called n times #212

Closed
wants to merge 4 commits into
from

3 participants

@Filirom1

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
bacchusrx and others added some commits Feb 16, 2012
@bacchusrx bacchusrx [fix] Handle vows for events that execute multiple times (fixes #191)
Add failing test for events that fire multiple times.

In `lib/vows/suite.js` add a property `count` to each vow which is incremented
every time the vow is executed.

In `runTest` (in `addVow` in `lib/vows.js`), on each execution increment
`batch.total` if a vow has been executed more than once.
5da488e
@bacchusrx bacchusrx Minor style fix. c34babb
@Filirom1 Filirom1 Expect a vow to be called n times 9897c4d
@Filirom1 Filirom1 Merge branch 'multiple-events' into expect e572ed2
@indexzero
vowsjs member

Seems reasonable. Will go into 0.9.0. Needs documentation though!

@indexzero indexzero added the v0.9.0 label Nov 4, 2014
@indexzero
vowsjs member

Thanks. Cherry-picked into v0.9.x branch.

@indexzero indexzero closed this Nov 22, 2014
@indexzero indexzero referenced this pull request Nov 22, 2014
Merged

v0.9.0-rc1 #328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment