Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4aedde8

Browse filesBrowse 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 <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent b48b80f commit 4aedde8
Copy full SHA for 4aedde8

File tree

Expand file treeCollapse file tree

4 files changed

+25
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+25
-5
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-num-args.js
+12-5Lines changed: 12 additions & 5 deletions
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
});
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-remove-all-listeners.js
+5Lines changed: 5 additions & 0 deletions
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+
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-remove-listeners.js
+6Lines changed: 6 additions & 0 deletions
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();
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-special-event-names.js
+2Lines changed: 2 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.