Skip to content

Commit 4aedde8

Browse files
vinimdocarmoevanlucas
authored andcommitted
test: expand test coverage of events.js
* test else path in emitMany function * test calling removeAllListeners() in a event emitter instance with no events at all * test calling removeListener() passing a event type that does not exist * test calling eventNames() in a event emitter instance with no events at all Refs: https://coverage.nodejs.org/coverage-ba776b3a56642d4c/root/events.js.html PR-URL: #10947 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent b48b80f commit 4aedde8

4 files changed

+25
-5
lines changed

test/parallel/test-event-emitter-num-args.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ const assert = require('assert');
44
const events = require('events');
55

66
const e = new events.EventEmitter();
7-
const num_args_emited = [];
7+
const num_args_emitted = [];
88

99
e.on('numArgs', function() {
1010
const numArgs = arguments.length;
11-
console.log('numArgs: ' + numArgs);
12-
num_args_emited.push(numArgs);
11+
num_args_emitted.push(numArgs);
1312
});
1413

15-
console.log('start');
14+
e.on('foo', function() {
15+
num_args_emitted.push(arguments.length);
16+
});
17+
18+
e.on('foo', function() {
19+
num_args_emitted.push(arguments.length);
20+
});
1621

1722
e.emit('numArgs');
1823
e.emit('numArgs', null);
@@ -21,6 +26,8 @@ e.emit('numArgs', null, null, null);
2126
e.emit('numArgs', null, null, null, null);
2227
e.emit('numArgs', null, null, null, null, null);
2328

29+
e.emit('foo', null, null, null, null);
30+
2431
process.on('exit', function() {
25-
assert.deepStrictEqual([0, 1, 2, 3, 4, 5], num_args_emited);
32+
assert.deepStrictEqual([0, 1, 2, 3, 4, 5, 4, 4], num_args_emitted);
2633
});

test/parallel/test-event-emitter-remove-all-listeners.js

+5
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ function listener() {}
7777
ee.removeAllListeners('baz');
7878
assert.strictEqual(ee.listeners('baz').length, 0);
7979
}
80+
81+
{
82+
const ee = new events.EventEmitter();
83+
assert.deepStrictEqual(ee, ee.removeAllListeners());
84+
}

test/parallel/test-event-emitter-remove-listeners.js

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ function listener2() {}
116116
ee.emit('hello');
117117
}
118118

119+
{
120+
const ee = new EventEmitter();
121+
122+
assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
123+
}
124+
119125
// Verify that the removed listener must be a function
120126
assert.throws(() => {
121127
const ee = new EventEmitter();

test/parallel/test-event-emitter-special-event-names.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const assert = require('assert');
77
const ee = new EventEmitter();
88
const handler = () => {};
99

10+
assert.deepStrictEqual(ee.eventNames(), []);
11+
1012
assert.strictEqual(ee._events.hasOwnProperty, undefined);
1113
assert.strictEqual(ee._events.toString, undefined);
1214

0 commit comments

Comments
 (0)