forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
1 parent
6ffedb9
commit 2fe65da
Showing
4 changed files
with
99 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -635,4 +635,6 @@ module.exports = { | |
kNewListener, | ||
kTrustEvent, | ||
kRemoveListener, | ||
kEvents, | ||
isEventTarget, | ||
}; |
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,38 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { | ||
deepStrictEqual, | ||
} = require('assert'); | ||
|
||
const { getEventListeners, EventEmitter } = require('events'); | ||
const { EventTarget } = require('internal/event_target'); | ||
|
||
// Test getEventListeners on EventEmitter | ||
{ | ||
const fn1 = common.mustNotCall(); | ||
const fn2 = common.mustNotCall(); | ||
const emitter = new EventEmitter(); | ||
emitter.on('foo', fn1); | ||
emitter.on('foo', fn2); | ||
emitter.on('baz', fn1); | ||
emitter.on('baz', fn1); | ||
deepStrictEqual(getEventListeners(emitter, 'foo'), [fn1, fn2]); | ||
deepStrictEqual(getEventListeners(emitter, 'bar'), []); | ||
deepStrictEqual(getEventListeners(emitter, 'baz'), [fn1, fn1]); | ||
} | ||
// Test getEventListeners on EventTarget | ||
{ | ||
const fn1 = common.mustNotCall(); | ||
const fn2 = common.mustNotCall(); | ||
const target = new EventTarget(); | ||
target.addEventListener('foo', fn1); | ||
target.addEventListener('foo', fn2); | ||
target.addEventListener('baz', fn1); | ||
target.addEventListener('baz', fn1); | ||
deepStrictEqual(getEventListeners(target, 'foo'), [fn1, fn2]); | ||
deepStrictEqual(getEventListeners(target, 'bar'), []); | ||
deepStrictEqual(getEventListeners(target, 'baz'), [fn1]); | ||
} |