Skip to content

Commit

Permalink
test: expand test coverage of events.js
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
vinimdocarmo authored and MylesBorins committed Mar 9, 2017
1 parent 406e623 commit 5cea223
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/parallel/test-event-emitter-num-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ var assert = require('assert');
var events = require('events');

const e = new events.EventEmitter();
const num_args_emited = [];
const num_args_emitted = [];

e.on('numArgs', function() {
var numArgs = arguments.length;
console.log('numArgs: ' + numArgs);
num_args_emited.push(numArgs);
const numArgs = arguments.length;
num_args_emitted.push(numArgs);
});

console.log('start');
e.on('foo', function() {
num_args_emitted.push(arguments.length);
});

e.on('foo', function() {
num_args_emitted.push(arguments.length);
});

e.emit('numArgs');
e.emit('numArgs', null);
Expand All @@ -21,6 +26,8 @@ e.emit('numArgs', null, null, null);
e.emit('numArgs', null, null, null, null);
e.emit('numArgs', null, null, null, null, null);

e.emit('foo', null, null, null, null);

process.on('exit', function() {
assert.deepStrictEqual([0, 1, 2, 3, 4, 5], num_args_emited);
assert.deepStrictEqual([0, 1, 2, 3, 4, 5, 4, 4], num_args_emitted);
});
6 changes: 6 additions & 0 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ function listener2() {}
ee.emit('hello');
}

{
const ee = new EventEmitter();

assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
}

// Verify that the removed listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-event-emitter-special-event-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const assert = require('assert');
const ee = new EventEmitter();
const handler = () => {};

assert.deepStrictEqual(ee.eventNames(), []);

assert.strictEqual(ee._events.hasOwnProperty, undefined);
assert.strictEqual(ee._events.toString, undefined);

Expand Down

0 comments on commit 5cea223

Please sign in to comment.