diff options
author | Matt Ezell <ezell.matt@gmail.com> | 2022-10-13 03:47:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 10:47:47 +0200 |
commit | 06ccb6d41e1b89bff587a6dbac698c912d1c1090 (patch) | |
tree | b886344c2212aefdf84594829c43a3a0d565fdce /cli/tests | |
parent | ba3d0da6ab3ff5f7e0a09b132b6ae113a8c8b782 (diff) |
chore: Added onbeforeunload to window type definition (#16251)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/testdata/run/onload/imported.ts | 3 | ||||
-rw-r--r-- | cli/tests/testdata/run/onload/main.out | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/onload/main.ts | 9 | ||||
-rw-r--r-- | cli/tests/testdata/run/onload/nest_imported.ts | 3 |
4 files changed, 16 insertions, 3 deletions
diff --git a/cli/tests/testdata/run/onload/imported.ts b/cli/tests/testdata/run/onload/imported.ts index 969f97e56..f4157b86f 100644 --- a/cli/tests/testdata/run/onload/imported.ts +++ b/cli/tests/testdata/run/onload/imported.ts @@ -3,10 +3,11 @@ import { assert } from "../../../../../test_util/std/testing/asserts.ts"; import "./nest_imported.ts"; const handler = (e: Event) => { - assert(!e.cancelable); + assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable); console.log(`got ${e.type} event in event handler (imported)`); }; window.addEventListener("load", handler); +window.addEventListener("beforeunload", handler); window.addEventListener("unload", handler); console.log("log from imported script"); diff --git a/cli/tests/testdata/run/onload/main.out b/cli/tests/testdata/run/onload/main.out index 9b1f454c9..b25d33fa8 100644 --- a/cli/tests/testdata/run/onload/main.out +++ b/cli/tests/testdata/run/onload/main.out @@ -5,6 +5,10 @@ got load event in event handler (nest_imported) got load event in event handler (imported) got load event in event handler (main) got load event in onload function +got beforeunload event in event handler (nest_imported) +got beforeunload event in event handler (imported) +got beforeunload event in event handler (main) +got beforeunload event in onbeforeunload function got unload event in event handler (nest_imported) got unload event in event handler (imported) got unload event in event handler (main) diff --git a/cli/tests/testdata/run/onload/main.ts b/cli/tests/testdata/run/onload/main.ts index 798b8aa7b..126627e34 100644 --- a/cli/tests/testdata/run/onload/main.ts +++ b/cli/tests/testdata/run/onload/main.ts @@ -6,12 +6,14 @@ assert(window.hasOwnProperty("onload")); assert(window.onload === null); const eventHandler = (e: Event) => { - assert(!e.cancelable); + assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable); console.log(`got ${e.type} event in event handler (main)`); }; window.addEventListener("load", eventHandler); +window.addEventListener("beforeunload", eventHandler); + window.addEventListener("unload", eventHandler); window.onload = (e: Event) => { @@ -19,6 +21,11 @@ window.onload = (e: Event) => { console.log(`got ${e.type} event in onload function`); }; +window.onbeforeunload = (e: BeforeUnloadEvent) => { + assert(e.cancelable); + console.log(`got ${e.type} event in onbeforeunload function`); +}; + window.onunload = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in onunload function`); diff --git a/cli/tests/testdata/run/onload/nest_imported.ts b/cli/tests/testdata/run/onload/nest_imported.ts index 351a3cb22..a942d2729 100644 --- a/cli/tests/testdata/run/onload/nest_imported.ts +++ b/cli/tests/testdata/run/onload/nest_imported.ts @@ -2,10 +2,11 @@ import { assert } from "../../../../../test_util/std/testing/asserts.ts"; const handler = (e: Event) => { - assert(!e.cancelable); + assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable); console.log(`got ${e.type} event in event handler (nest_imported)`); }; window.addEventListener("load", handler); +window.addEventListener("beforeunload", handler); window.addEventListener("unload", handler); console.log("log from nest_imported script"); |