Permalink
Browse files

test: increase coverage for lib/events.js

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 Trott committed Dec 1, 2016
1 parent 20fa6e7 commit a912b791d4dd10d694c8b278fea9345f377adf58
Showing with 14 additions and 0 deletions.
  1. +14 −0 test/parallel/test-event-emitter-listeners.js
@@ -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();
@@ -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 a912b79

Please sign in to comment.