node/test/parallel/test-whatwg-events-event-constructors.js
Daeyeon Jeong 3f7f62f6bc
events: improve Event compatibility
This fixes `Event` constructor to improve `Event Web API`
compatibility.

The test added was written by referring to
`wpt@dom/events/Event-constructors.any.js`.

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com

PR-URL: https://github.com/nodejs/node/pull/43461
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-07-08 09:12:13 +01:00

30 lines
784 B
JavaScript

'use strict';
require('../common');
const { test, assert_equals, assert_array_equals } =
require('../common/wpt').harness;
// Source: https://github.com/web-platform-tests/wpt/blob/6cef1d2087d6a07d7cc6cee8cf207eec92e27c5f/dom/events/Event-constructors.any.js#L91-L112
test(function() {
const called = [];
const ev = new Event('Xx', {
get cancelable() {
called.push('cancelable');
return false;
},
get bubbles() {
called.push('bubbles');
return true;
},
get sweet() {
called.push('sweet');
return 'x';
},
});
assert_array_equals(called, ['bubbles', 'cancelable']);
assert_equals(ev.type, 'Xx');
assert_equals(ev.bubbles, true);
assert_equals(ev.cancelable, false);
assert_equals(ev.sweet, undefined);
});