Browse Source

test: improve coverage on removeListeners functions

PR-URL: https://github.com/nodejs/node/pull/11140
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v4.x
matsuda-koushi 8 years ago
committed by Myles Borins
parent
commit
1db89d4009
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 12
      test/parallel/test-event-emitter-remove-all-listeners.js
  2. 21
      test/parallel/test-event-emitter-remove-listeners.js

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

@ -77,3 +77,15 @@ function listener() {}
ee.removeAllListeners('baz');
assert.strictEqual(ee.listeners('baz').length, 0);
}
{
const ee = new events.EventEmitter();
assert.deepStrictEqual(ee, ee.removeAllListeners());
}
{
const ee = new events.EventEmitter();
ee._events = undefined;
assert.strictEqual(ee, ee.removeAllListeners());
}

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

@ -115,3 +115,24 @@ function listener2() {}
}));
ee.emit('hello');
}
{
const ee = new events.EventEmitter();
assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
}
// Verify that the removed listener must be a function
assert.throws(() => {
const ee = new events.EventEmitter();
ee.removeListener('foo', null);
}, /^TypeError: listener must be a function$/);
{
const ee = new events.EventEmitter();
const listener = () => {};
ee._events = undefined;
const e = ee.removeListener('foo', listener);
assert.strictEqual(e, ee);
}

Loading…
Cancel
Save