Skip to content

Commit

Permalink
events: add event-target tests
Browse files Browse the repository at this point in the history
PR-URL: #33623
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
benjamingr authored and Benjamin Gruenbaum committed May 31, 2020
1 parent b2b95eb commit df4eda2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/parallel/test-eventtarget.js
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 @@ -52,7 +52,7 @@ ok(EventTarget);
strictEqual(ev.type, 'foo');
}
{
const ev = new Event('foo');
const ev = new Event('foo');
strictEqual(ev.cancelBubble, false);
ev.cancelBubble = true;
strictEqual(ev.cancelBubble, true);
Expand Down Expand Up @@ -438,3 +438,33 @@ const ev = new Event('foo');
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());

0 comments on commit df4eda2

Please sign in to comment.