blob: 3b690324e582bab517ad0e4487807313d9c2e148 [file] [log] [blame]
Domenic Denicola306b7ef2020-04-07 14:19:161<!DOCTYPE html>
2<meta charset="utf-8">
3<title>Window extends EventTarget</title>
4<link rel="help" href="https://github.com/jsdom/jsdom/issues/2830">
5<script src="/resources/testharness.js"></script>
6<script src="/resources/testharnessreport.js"></script>
7
8<body>
9<script>
10"use strict";
11
12test(() => {
13
14 assert_equals(window.addEventListener, EventTarget.prototype.addEventListener);
15 assert_equals(window.removeEventListener, EventTarget.prototype.removeEventListener);
16 assert_equals(window.dispatchEvent, EventTarget.prototype.dispatchEvent);
17
18}, "EventTarget methods on Window instances are inherited from the EventTarget prototype");
19
20test(() => {
21
22 const kCustom = "custom-event";
23 const customEvent = new CustomEvent(kCustom, {
24 bubbles: true
25 });
26
27 let target;
28 window.addEventListener.call(document.body, kCustom, function () {
29 target = this;
30 });
31
32 document.body.dispatchEvent(customEvent);
33
34 assert_equals(target, document.body);
35
36}, "window.addEventListener respects custom `this`");
37
38test(() => {
39
40 const kCustom = "custom-event";
41 const customEvent = new CustomEvent(kCustom, {
42 bubbles: true
43 });
44
45 let target;
46 window.addEventListener.call(null, kCustom, function () {
47 target = this;
48 });
49
50 document.body.dispatchEvent(customEvent);
51
52 assert_equals(target, window);
53
54}, "window.addEventListener treats nullish `this` as `window`");
55</script>