Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1cdfaa8

Browse filesBrowse files
benjamingrtargos
authored andcommitted
events: add a few tests
PR-URL: #35806 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent d3f1cde commit 1cdfaa8
Copy full SHA for 1cdfaa8

File tree

Expand file treeCollapse file tree

2 files changed

+34
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
7272
}, 'isTrusted').get;
7373

7474
class Event {
75-
constructor(type, options) {
75+
constructor(type, options = null) {
7676
if (arguments.length === 0)
7777
throw new ERR_MISSING_ARGS('type');
78-
if (options != null)
78+
if (options !== null)
7979
validateObject(options, 'options');
8080
const { cancelable, bubbles, composed } = { ...options };
8181
this[kCancelable] = !!cancelable;
Collapse file

‎test/parallel/test-eventtarget.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-eventtarget.js
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ let asyncTest = Promise.resolve();
414414
}
415415

416416
{
417+
// Event Statics
417418
strictEqual(Event.NONE, 0);
418419
strictEqual(Event.CAPTURING_PHASE, 1);
419420
strictEqual(Event.AT_TARGET, 2);
@@ -424,6 +425,8 @@ let asyncTest = Promise.resolve();
424425
strictEqual(e.eventPhase, Event.AT_TARGET);
425426
}), { once: true });
426427
target.dispatchEvent(new Event('foo'));
428+
// Event is a function
429+
strictEqual(Event.length, 1);
427430
}
428431

429432
{
@@ -485,3 +488,32 @@ let asyncTest = Promise.resolve();
485488
eventTarget.dispatchEvent(event);
486489
strictEqual(event.target, eventTarget);
487490
}
491+
{
492+
// Event target exported keys
493+
const eventTarget = new EventTarget();
494+
deepStrictEqual(Object.keys(eventTarget), []);
495+
deepStrictEqual(Object.getOwnPropertyNames(eventTarget), []);
496+
const parentKeys = Object.keys(Object.getPrototypeOf(eventTarget)).sort();
497+
const keys = ['addEventListener', 'dispatchEvent', 'removeEventListener'];
498+
deepStrictEqual(parentKeys, keys);
499+
}
500+
{
501+
// Subclassing
502+
class SubTarget extends EventTarget {}
503+
const target = new SubTarget();
504+
target.addEventListener('foo', common.mustCall());
505+
target.dispatchEvent(new Event('foo'));
506+
}
507+
{
508+
// Test event order
509+
const target = new EventTarget();
510+
let state = 0;
511+
target.addEventListener('foo', common.mustCall(() => {
512+
strictEqual(state, 0);
513+
state++;
514+
}));
515+
target.addEventListener('foo', common.mustCall(() => {
516+
strictEqual(state, 1);
517+
}));
518+
target.dispatchEvent(new Event('foo'));
519+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.