Skip to content

Commit

Permalink
test: increase coverage for lib/events.js
Browse files Browse the repository at this point in the history
Adds tests for the case in which listeners() is invoked on a
EventEmitter with no events.

Adds a new test case for the situation in which a class
inherits from the EventEmitter but overrides the constructor
in the EventEmitter so that the _events is never set.

PR-URL: #9865
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
captainsafia authored and MylesBorins committed Dec 20, 2016
1 parent 6632b3d commit afbd8df
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/parallel/test-event-emitter-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
require('../common');
const assert = require('assert');
const events = require('events');
const util = require('util');

function listener() {}
function listener2() {}
class TestStream { constructor() { } }
util.inherits(TestStream, events.EventEmitter);

{
const ee = new events.EventEmitter();
Expand Down Expand Up @@ -36,3 +39,14 @@ function listener2() {}
assert.deepStrictEqual(ee.listeners('foo'), [listener, listener2]);
assert.deepStrictEqual(eeListenersCopy, [listener]);
}

{
const ee = new events.EventEmitter();
ee._events = undefined;
assert.deepStrictEqual(ee.listeners('foo'), []);
}

{
const s = new TestStream();
assert.deepStrictEqual(s.listeners('foo'), []);
}

0 comments on commit afbd8df

Please sign in to comment.