1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-14 19:37:59 -05:00
denoland-deno/cli/tests/testdata/run/onload/main.ts

35 lines
972 B
TypeScript
Raw Normal View History

// deno-lint-ignore-file no-window-prefix no-prototype-builtins
import { assert } from "../../../../../test_util/std/assert/mod.ts";
2019-07-16 00:19:26 -04:00
import "./imported.ts";
assert(window.hasOwnProperty("onload"));
assert(window.onload === null);
const eventHandler = (e: Event) => {
assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
2019-10-02 11:32:51 -04:00
console.log(`got ${e.type} event in event handler (main)`);
};
window.addEventListener("load", eventHandler);
window.addEventListener("beforeunload", eventHandler);
2019-10-02 11:32:51 -04:00
window.addEventListener("unload", eventHandler);
2019-07-16 00:19:26 -04:00
window.onload = (e: Event) => {
2019-10-02 11:32:51 -04:00
assert(!e.cancelable);
2019-07-16 00:19:26 -04:00
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) => {
2019-10-02 11:32:51 -04:00
assert(!e.cancelable);
console.log(`got ${e.type} event in onunload function`);
};
2019-07-16 00:19:26 -04:00
console.log("log from main");