-
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.
events: add listener argument to listenerCount
- Loading branch information
1 parent
5092346
commit eb50d19
Showing
3 changed files
with
73 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const EventEmitter = require('events'); | ||
const assert = require('assert'); | ||
|
||
const EE = new EventEmitter(); | ||
const handler = common.mustCall(undefined, 2); | ||
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.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); |