From a6377a96dd3e092ce76b9ddf1fbf2a75216dfba5 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 30 Nov 2016 22:04:28 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/9865 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Myles Borins --- test/parallel/test-event-emitter-listeners.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index cfb2dafb121e03..8aedd8fc3766bd 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/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'), []); +}