1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00
denoland-deno/tests/testdata/run/onload/main.ts
Bartek Iwańczuk 57541b48ba
test: replace usage of window with globalThis (#25284)
Fixes several tests blocking https://github.com/denoland/deno/pull/25213
by replacing `window` global that is gone in Deno 2 with `globalThis`.

Also adjusted a few tests using deprecated `rid` field.
2024-08-29 01:56:15 +02:00

34 lines
956 B
TypeScript

// deno-lint-ignore-file no-prototype-builtins
import { assert } from "@std/assert";
import "./imported.ts";
assert(globalThis.hasOwnProperty("onload"));
assert(globalThis.onload === null);
const eventHandler = (e: Event) => {
assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
console.log(`got ${e.type} event in event handler (main)`);
};
globalThis.addEventListener("load", eventHandler);
globalThis.addEventListener("beforeunload", eventHandler);
globalThis.addEventListener("unload", eventHandler);
globalThis.onload = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in onload function`);
};
globalThis.onbeforeunload = (e: BeforeUnloadEvent) => {
assert(e.cancelable);
console.log(`got ${e.type} event in onbeforeunload function`);
};
globalThis.onunload = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in onunload function`);
};
console.log("log from main");