Browse Source

test: exercise once() with varying arguments

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: https://github.com/nodejs/node/pull/13524
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6.x
cjihrig 8 years ago
committed by Myles Borins
parent
commit
a37165a2cc
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 20
      test/parallel/test-event-emitter-once.js

20
test/parallel/test-event-emitter-once.js

@ -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);
}
}

Loading…
Cancel
Save