-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor large event emitter tests
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
1 parent
2d503b1
commit 7641f9a
Showing
3 changed files
with
191 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
var assert = require('assert'); | ||
var events = require('events'); | ||
const assert = require('assert'); | ||
const events = require('events'); | ||
|
||
function listener() {} | ||
function listener2() {} | ||
|
||
var e1 = new events.EventEmitter(); | ||
e1.on('foo', listener); | ||
var fooListeners = e1.listeners('foo'); | ||
assert.deepStrictEqual(e1.listeners('foo'), [listener]); | ||
e1.removeAllListeners('foo'); | ||
assert.deepStrictEqual(e1.listeners('foo'), []); | ||
assert.deepStrictEqual(fooListeners, [listener]); | ||
{ | ||
const ee = new events.EventEmitter(); | ||
ee.on('foo', listener); | ||
const fooListeners = ee.listeners('foo'); | ||
assert.deepStrictEqual(ee.listeners('foo'), [listener]); | ||
ee.removeAllListeners('foo'); | ||
assert.deepStrictEqual(ee.listeners('foo'), []); | ||
assert.deepStrictEqual(fooListeners, [listener]); | ||
} | ||
|
||
var e2 = new events.EventEmitter(); | ||
e2.on('foo', listener); | ||
var e2ListenersCopy = e2.listeners('foo'); | ||
assert.deepStrictEqual(e2ListenersCopy, [listener]); | ||
assert.deepStrictEqual(e2.listeners('foo'), [listener]); | ||
e2ListenersCopy.push(listener2); | ||
assert.deepStrictEqual(e2.listeners('foo'), [listener]); | ||
assert.deepStrictEqual(e2ListenersCopy, [listener, listener2]); | ||
{ | ||
const ee = new events.EventEmitter(); | ||
ee.on('foo', listener); | ||
const eeListenersCopy = ee.listeners('foo'); | ||
assert.deepStrictEqual(eeListenersCopy, [listener]); | ||
assert.deepStrictEqual(ee.listeners('foo'), [listener]); | ||
eeListenersCopy.push(listener2); | ||
assert.deepStrictEqual(ee.listeners('foo'), [listener]); | ||
assert.deepStrictEqual(eeListenersCopy, [listener, listener2]); | ||
} | ||
|
||
var e3 = new events.EventEmitter(); | ||
e3.on('foo', listener); | ||
var e3ListenersCopy = e3.listeners('foo'); | ||
e3.on('foo', listener2); | ||
assert.deepStrictEqual(e3.listeners('foo'), [listener, listener2]); | ||
assert.deepStrictEqual(e3ListenersCopy, [listener]); | ||
{ | ||
const ee = new events.EventEmitter(); | ||
ee.on('foo', listener); | ||
const eeListenersCopy = ee.listeners('foo'); | ||
ee.on('foo', listener2); | ||
assert.deepStrictEqual(ee.listeners('foo'), [listener, listener2]); | ||
assert.deepStrictEqual(eeListenersCopy, [listener]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.