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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
e71c278288
commit
bee83e0bbc
@ -4,15 +4,20 @@ const assert = require('assert');
|
||||
const events = require('events');
|
||||
|
||||
const e = new events.EventEmitter();
|
||||
const num_args_emited = [];
|
||||
const num_args_emitted = [];
|
||||
|
||||
e.on('numArgs', function() {
|
||||
const numArgs = arguments.length;
|
||||
console.log('numArgs: ' + numArgs);
|
||||
num_args_emited.push(numArgs);
|
||||
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);
|
||||
@ -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);
|
||||
});
|
||||
|
@ -77,3 +77,8 @@ function listener() {}
|
||||
ee.removeAllListeners('baz');
|
||||
assert.strictEqual(ee.listeners('baz').length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const ee = new events.EventEmitter();
|
||||
assert.deepStrictEqual(ee, ee.removeAllListeners());
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user