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 addaleax committed Dec 5, 2016
1 parent 65cda7f commit a6377a9
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 @@ -49,3 +52,14 @@ function listener2() {}
ee.once('foo', listener2);
assert.deepStrictEqual(ee.listeners('foo'), [listener, listener2]);
}

{
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 a6377a9

Please sign in to comment.