-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: add listener argument to listenerCount
PR-URL: #46523 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
- Loading branch information
1 parent
19b5d07
commit 2eb8875
Showing
4 changed files
with
82 additions
and
5 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
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
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const EventEmitter = require('events'); | ||
const assert = require('assert'); | ||
|
||
const EE = new EventEmitter(); | ||
const handler = common.mustCall(undefined, 3); | ||
const anotherHandler = common.mustCall(); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 0); | ||
assert.strictEqual(EE.listenerCount('event', handler), 0); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0); | ||
|
||
EE.on('event', handler); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 1); | ||
assert.strictEqual(EE.listenerCount('event', handler), 1); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0); | ||
|
||
EE.once('event', anotherHandler); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 2); | ||
assert.strictEqual(EE.listenerCount('event', handler), 1); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 1); | ||
|
||
assert.strictEqual(EE.listenerCount('another-event'), 0); | ||
assert.strictEqual(EE.listenerCount('another-event', handler), 0); | ||
assert.strictEqual(EE.listenerCount('another-event', anotherHandler), 0); | ||
|
||
EE.once('event', handler); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 3); | ||
assert.strictEqual(EE.listenerCount('event', handler), 2); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 1); | ||
|
||
EE.emit('event'); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 1); | ||
assert.strictEqual(EE.listenerCount('event', handler), 1); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0); | ||
|
||
EE.emit('event'); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 1); | ||
assert.strictEqual(EE.listenerCount('event', handler), 1); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0); | ||
|
||
EE.off('event', handler); | ||
|
||
assert.strictEqual(EE.listenerCount('event'), 0); | ||
assert.strictEqual(EE.listenerCount('event', handler), 0); | ||
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0); |