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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Jul 17, 2017
1 parent 79592fe commit a37165a
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 @@ -34,3 +34,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 a37165a

Please sign in to comment.