Skip to content

Commit

Permalink
test: exercise once() with varying arguments
Browse files Browse the repository at this point in the history
This commit regains test coverage for EventEmitter#once() with
four or more arguments. To avoid similar regressions in the
future, once() is called with enough arguments to cover all of
the separate code paths.

PR-URL: #13524
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig committed Jun 9, 2017
1 parent 1f9b1aa commit 637819b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/parallel/test-event-emitter-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ assert.throws(() => {

ee.once('foo', null);
}, /^TypeError: "listener" argument must be a function$/);

{
// once() has different code paths based on the number of arguments being
// emitted. Verify that all of the cases are covered.
const maxArgs = 4;

for (let i = 0; i <= maxArgs; ++i) {
const ee = new EventEmitter();
const args = ['foo'];

for (let j = 0; j < i; ++j)
args.push(j);

ee.once('foo', common.mustCall((...params) => {
assert.deepStrictEqual(params, args.slice(1));
}));

EventEmitter.prototype.emit.apply(ee, args);
}
}

0 comments on commit 637819b

Please sign in to comment.