Skip to content

Commit

Permalink
test: refactor large event emitter tests
Browse files Browse the repository at this point in the history
This commit splits several large event emitter tests into smaller
block scoped tests. This keeps the tests more isolated. This
commit also replaces var with const, assert.equal() with
assert.stictEqual(), and other small enhancements.

PR-URL: #6446
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and MylesBorins committed Dec 21, 2016
1 parent 7fa8063 commit b612003
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events');
const events = require('events');

function listener1() {}
function listener2() {}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();
ee.on('hello', listener1);
ee.on('removeListener', common.mustCall((name, cb) => {
assert.strictEqual(name, 'hello');
Expand All @@ -18,15 +18,15 @@ function listener2() {}
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();
ee.on('hello', listener1);
ee.on('removeListener', common.fail);
ee.removeListener('hello', listener2);
assert.deepStrictEqual([listener1], ee.listeners('hello'));
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();
ee.on('hello', listener1);
ee.on('hello', listener2);
ee.once('removeListener', common.mustCall((name, cb) => {
Expand All @@ -46,7 +46,7 @@ function listener2() {}
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();

function remove1() {
common.fail('remove1 should not have been called');
Expand All @@ -67,7 +67,7 @@ function listener2() {}
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();
ee.on('hello', listener1);
ee.on('hello', listener2);
ee.once('removeListener', common.mustCall((name, cb) => {
Expand All @@ -87,7 +87,7 @@ function listener2() {}
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();
const listener3 = common.mustCall(() => {
ee.removeListener('hello', listener4);
}, 2);
Expand All @@ -106,7 +106,7 @@ function listener2() {}
}

{
const ee = new EventEmitter();
const ee = new events.EventEmitter();

ee.once('hello', listener1);
ee.on('removeListener', common.mustCall((eventName, listener) => {
Expand Down

0 comments on commit b612003

Please sign in to comment.