Skip to content

Commit 12036a1

Browse files
cjihrigaddaleax
authored andcommitted
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: #13524 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1f88cbd commit 12036a1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,23 @@ assert.throws(() => {
5555

5656
ee.once('foo', null);
5757
}, /^TypeError: "listener" argument must be a function$/);
58+
59+
{
60+
// once() has different code paths based on the number of arguments being
61+
// emitted. Verify that all of the cases are covered.
62+
const maxArgs = 4;
63+
64+
for (let i = 0; i <= maxArgs; ++i) {
65+
const ee = new EventEmitter();
66+
const args = ['foo'];
67+
68+
for (let j = 0; j < i; ++j)
69+
args.push(j);
70+
71+
ee.once('foo', common.mustCall((...params) => {
72+
assert.deepStrictEqual(params, args.slice(1));
73+
}));
74+
75+
EventEmitter.prototype.emit.apply(ee, args);
76+
}
77+
}

0 commit comments

Comments
 (0)