Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
throws,
} = require('assert');

const { once } = require('events');
const { once, on } = require('events');

// The globals are defined.
ok(Event);
Expand Down Expand Up @@ -439,3 +439,33 @@ ok(EventTarget);
const event = new Event('');
strictEqual(event.toString(), '[object Event]');
}
{
const target = new EventTarget();
const ev = new Event('toString');
const fn = common.mustCall((event) => strictEqual(event.type, 'toString'));
target.addEventListener('toString', fn);
target.dispatchEvent(ev);
}
{
const target = new EventTarget();
const ev = new Event('__proto__');
const fn = common.mustCall((event) => strictEqual(event.type, '__proto__'));
target.addEventListener('__proto__', fn);
target.dispatchEvent(ev);
}

(async () => {
// test NodeEventTarget async-iterability
const emitter = new NodeEventTarget();
const event = new Event('foo');
const interval = setInterval(() => emitter.dispatchEvent(event), 0);
let count = 0;
for await (const [ item ] of on(emitter, 'foo')) {
count++;
strictEqual(item.type, 'foo');
if (count > 5) {
break;
}
}
clearInterval(interval);
})().then(common.mustCall());