From 637819b7abe456b5971878126bd25c6348f9db0b Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 7 Jun 2017 12:50:55 -0400 Subject: [PATCH] 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 Reviewed-By: James M Snell --- test/parallel/test-event-emitter-once.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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); + } +}