1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/js/event_test.ts
2019-01-05 10:02:44 -05:00

70 lines
2.1 KiB
TypeScript

// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { test, assertEqual } from "./test_util.ts";
test(function eventInitializedWithType() {
const type = "click";
const event = new Event(type);
assertEqual(event.isTrusted, false);
assertEqual(event.target, null);
assertEqual(event.currentTarget, null);
assertEqual(event.type, "click");
assertEqual(event.bubbles, false);
assertEqual(event.cancelable, false);
});
test(function eventInitializedWithTypeAndDict() {
const init = "submit";
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
const event = new Event(init, eventInitDict);
assertEqual(event.isTrusted, false);
assertEqual(event.target, null);
assertEqual(event.currentTarget, null);
assertEqual(event.type, "submit");
assertEqual(event.bubbles, true);
assertEqual(event.cancelable, true);
});
test(function eventComposedPathSuccess() {
const type = "click";
const event = new Event(type);
const composedPath = event.composedPath();
assertEqual(composedPath, []);
});
test(function eventStopPropagationSuccess() {
const type = "click";
const event = new Event(type);
assertEqual(event.cancelBubble, false);
event.stopPropagation();
assertEqual(event.cancelBubble, true);
});
test(function eventStopImmediatePropagationSuccess() {
const type = "click";
const event = new Event(type);
assertEqual(event.cancelBubble, false);
assertEqual(event.cancelBubbleImmediately, false);
event.stopImmediatePropagation();
assertEqual(event.cancelBubble, true);
assertEqual(event.cancelBubbleImmediately, true);
});
test(function eventPreventDefaultSuccess() {
const type = "click";
const event = new Event(type);
assertEqual(event.defaultPrevented, false);
event.preventDefault();
assertEqual(event.defaultPrevented, false);
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
const cancelableEvent = new Event(type, eventInitDict);
assertEqual(cancelableEvent.defaultPrevented, false);
cancelableEvent.preventDefault();
assertEqual(cancelableEvent.defaultPrevented, true);
});