diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js index 6823a9805e8762..dd4f5133a198d9 100644 --- a/test/parallel/test-event-emitter-once.js +++ b/test/parallel/test-event-emitter-once.js @@ -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); + } +}