0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/event_test.ts

83 lines
2.5 KiB
TypeScript
Raw Normal View History

2019-01-21 14:03:30 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assertEquals } from "./test_util.ts";
2019-01-05 10:02:44 -05:00
test(function eventInitializedWithType() {
const type = "click";
const event = new Event(type);
assertEquals(event.isTrusted, false);
assertEquals(event.target, null);
assertEquals(event.currentTarget, null);
assertEquals(event.type, "click");
assertEquals(event.bubbles, false);
assertEquals(event.cancelable, false);
2019-01-05 10:02:44 -05:00
});
test(function eventInitializedWithTypeAndDict() {
const init = "submit";
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
const event = new Event(init, eventInitDict);
assertEquals(event.isTrusted, false);
assertEquals(event.target, null);
assertEquals(event.currentTarget, null);
assertEquals(event.type, "submit");
assertEquals(event.bubbles, true);
assertEquals(event.cancelable, true);
2019-01-05 10:02:44 -05:00
});
test(function eventComposedPathSuccess() {
const type = "click";
const event = new Event(type);
const composedPath = event.composedPath();
assertEquals(composedPath, []);
2019-01-05 10:02:44 -05:00
});
test(function eventStopPropagationSuccess() {
const type = "click";
const event = new Event(type);
assertEquals(event.cancelBubble, false);
2019-01-05 10:02:44 -05:00
event.stopPropagation();
assertEquals(event.cancelBubble, true);
2019-01-05 10:02:44 -05:00
});
test(function eventStopImmediatePropagationSuccess() {
const type = "click";
const event = new Event(type);
assertEquals(event.cancelBubble, false);
assertEquals(event.cancelBubbleImmediately, false);
2019-01-05 10:02:44 -05:00
event.stopImmediatePropagation();
assertEquals(event.cancelBubble, true);
assertEquals(event.cancelBubbleImmediately, true);
2019-01-05 10:02:44 -05:00
});
test(function eventPreventDefaultSuccess() {
const type = "click";
const event = new Event(type);
assertEquals(event.defaultPrevented, false);
2019-01-05 10:02:44 -05:00
event.preventDefault();
assertEquals(event.defaultPrevented, false);
2019-01-05 10:02:44 -05:00
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
const cancelableEvent = new Event(type, eventInitDict);
assertEquals(cancelableEvent.defaultPrevented, false);
2019-01-05 10:02:44 -05:00
cancelableEvent.preventDefault();
assertEquals(cancelableEvent.defaultPrevented, true);
2019-01-05 10:02:44 -05:00
});
test(function eventInitializedWithNonStringType() {
const type = undefined;
const event = new Event(type);
assertEquals(event.isTrusted, false);
assertEquals(event.target, null);
assertEquals(event.currentTarget, null);
assertEquals(event.type, "undefined");
assertEquals(event.bubbles, false);
assertEquals(event.cancelable, false);
});