Skip to content

Commit d2b9e56

Browse files
benjamingrBenjamin Gruenbaum
authored and
Benjamin Gruenbaum
committed
events: add event-target tests
PR-URL: nodejs#33623 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 3fff349 commit d2b9e56

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

test/parallel/test-eventtarget.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
throws,
1616
} = require('assert');
1717

18-
const { once } = require('events');
18+
const { once, on } = require('events');
1919

2020
// The globals are defined.
2121
ok(Event);
@@ -70,7 +70,7 @@ ok(EventTarget);
7070
strictEqual(ev.type, 'foo');
7171
}
7272
{
73-
const ev = new Event('foo');
73+
const ev = new Event('foo');
7474
strictEqual(ev.cancelBubble, false);
7575
ev.cancelBubble = true;
7676
strictEqual(ev.cancelBubble, true);
@@ -457,3 +457,33 @@ const ev = new Event('foo');
457457
const event = new Event('');
458458
strictEqual(event.toString(), '[object Event]');
459459
}
460+
{
461+
const target = new EventTarget();
462+
const ev = new Event('toString');
463+
const fn = common.mustCall((event) => strictEqual(event.type, 'toString'));
464+
target.addEventListener('toString', fn);
465+
target.dispatchEvent(ev);
466+
}
467+
{
468+
const target = new EventTarget();
469+
const ev = new Event('__proto__');
470+
const fn = common.mustCall((event) => strictEqual(event.type, '__proto__'));
471+
target.addEventListener('__proto__', fn);
472+
target.dispatchEvent(ev);
473+
}
474+
475+
(async () => {
476+
// test NodeEventTarget async-iterability
477+
const emitter = new NodeEventTarget();
478+
const event = new Event('foo');
479+
const interval = setInterval(() => emitter.dispatchEvent(event), 0);
480+
let count = 0;
481+
for await (const [ item ] of on(emitter, 'foo')) {
482+
count++;
483+
strictEqual(item.type, 'foo');
484+
if (count > 5) {
485+
break;
486+
}
487+
}
488+
clearInterval(interval);
489+
})().then(common.mustCall());

0 commit comments

Comments
 (0)