Skip to content

Commit

Permalink
test: improve coverage on removeListeners functions
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
matsuda-koushi authored and jasnell committed Mar 7, 2017
1 parent f87a422 commit 039f3f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/parallel/test-event-emitter-remove-all-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 21 additions & 0 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 039f3f4

Please sign in to comment.