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
Nayeem Rahman e55e4a2838 Remove some non-standard web API constructors (#2970)
This removes the EventListener, EventInit and CustomEventInit constructors from the userland globals. The type exports stay.

I removed the internal classes as well. EventListener's implementation seemed to be doing some bookkeeping on handled events but that's not being used anywhere so I assume it's old debug stuff. The other two are completely redundant.
2019-09-17 12:17:12 -04:00

95 lines
3 KiB
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assertEquals, assertNotEquals } from "./test_util.ts";
test(function eventInitializedWithType(): void {
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);
});
test(function eventInitializedWithTypeAndDict(): void {
const init = "submit";
const eventInit = { bubbles: true, cancelable: true } as EventInit;
const event = new Event(init, eventInit);
assertEquals(event.isTrusted, false);
assertEquals(event.target, null);
assertEquals(event.currentTarget, null);
assertEquals(event.type, "submit");
assertEquals(event.bubbles, true);
assertEquals(event.cancelable, true);
});
test(function eventComposedPathSuccess(): void {
const type = "click";
const event = new Event(type);
const composedPath = event.composedPath();
assertEquals(composedPath, []);
});
test(function eventStopPropagationSuccess(): void {
const type = "click";
const event = new Event(type);
assertEquals(event.cancelBubble, false);
event.stopPropagation();
assertEquals(event.cancelBubble, true);
});
test(function eventStopImmediatePropagationSuccess(): void {
const type = "click";
const event = new Event(type);
assertEquals(event.cancelBubble, false);
assertEquals(event.cancelBubbleImmediately, false);
event.stopImmediatePropagation();
assertEquals(event.cancelBubble, true);
assertEquals(event.cancelBubbleImmediately, true);
});
test(function eventPreventDefaultSuccess(): void {
const type = "click";
const event = new Event(type);
assertEquals(event.defaultPrevented, false);
event.preventDefault();
assertEquals(event.defaultPrevented, false);
const eventInit = { bubbles: true, cancelable: true } as EventInit;
const cancelableEvent = new Event(type, eventInit);
assertEquals(cancelableEvent.defaultPrevented, false);
cancelableEvent.preventDefault();
assertEquals(cancelableEvent.defaultPrevented, true);
});
test(function eventInitializedWithNonStringType(): void {
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);
});
// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
test(function eventIsTrusted(): void {
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
assertNotEquals(desc1, undefined);
assertEquals(typeof desc1.get, "function");
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
assertNotEquals(desc2, undefined);
assertEquals(typeof desc2.get, "function");
assertEquals(desc1.get, desc2.get);
});