From 039f3f447d2c1c836e6f5e1d7a616631e5e1c699 Mon Sep 17 00:00:00 2001 From: matsuda-koushi Date: Fri, 3 Feb 2017 15:59:12 +0900 Subject: [PATCH] test: improve coverage on removeListeners functions PR-URL: https://github.com/nodejs/node/pull/11140 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Italo A. Casas Reviewed-By: Michael Dawson --- ...test-event-emitter-remove-all-listeners.js | 12 +++++++++++ .../test-event-emitter-remove-listeners.js | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/parallel/test-event-emitter-remove-all-listeners.js b/test/parallel/test-event-emitter-remove-all-listeners.js index e32a0e3f94f5b4..bed6c22f3f5876 100644 --- a/test/parallel/test-event-emitter-remove-all-listeners.js +++ b/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()); +} + diff --git a/test/parallel/test-event-emitter-remove-listeners.js b/test/parallel/test-event-emitter-remove-listeners.js index 912eefc9f4bf1e..f35a1c49cdb3ff 100644 --- a/test/parallel/test-event-emitter-remove-listeners.js +++ b/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); +}