Skip to content

Commit

Permalink
events: add event-target tests
Browse files Browse the repository at this point in the history
PR-URL: #34015
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
jasnell authored and codebytere committed Jun 27, 2020
1 parent 2724514 commit 5ce1533
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
throws,
} = require('assert');

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

// The globals are defined.
ok(Event);
Expand Down Expand Up @@ -71,7 +71,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 @@ -528,3 +528,35 @@ const ev = new Event('foo');
}), { once: true });
target.dispatchEvent(new Event('foo'));
}

{
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 interval = setInterval(() => {
emitter.dispatchEvent(new Event('foo'));
}, 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 5ce1533

Please sign in to comment.