mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
8d96dffa41
Rewrite "testPerm" helper function used for testing of internal runtime code. It's been renamed to "unitTest" and provides API that is extensible in the future by accepting optional "UnitTestOptions" argument. "test" helper was also removed and replaced by overloaded version of "unitTest" that takes only function argument. "UnitTestOptions" currently supports "perms" and "skip" options, where former works exactly as first argument to "testPerm" did, while the latter allows to conditionally skip tests.
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
import { unitTest, assertEquals, assert } from "./test_util.ts";
|
|
|
|
unitTest(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);
|
|
});
|
|
|
|
unitTest(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);
|
|
});
|
|
|
|
unitTest(function eventComposedPathSuccess(): void {
|
|
const type = "click";
|
|
const event = new Event(type);
|
|
const composedPath = event.composedPath();
|
|
|
|
assertEquals(composedPath, []);
|
|
});
|
|
|
|
unitTest(function eventStopPropagationSuccess(): void {
|
|
const type = "click";
|
|
const event = new Event(type);
|
|
|
|
assertEquals(event.cancelBubble, false);
|
|
event.stopPropagation();
|
|
assertEquals(event.cancelBubble, true);
|
|
});
|
|
|
|
unitTest(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);
|
|
});
|
|
|
|
unitTest(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);
|
|
});
|
|
|
|
unitTest(function eventInitializedWithNonStringType(): void {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const type: any = 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
|
|
unitTest(function eventIsTrusted(): void {
|
|
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
|
assert(desc1);
|
|
assertEquals(typeof desc1.get, "function");
|
|
|
|
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
|
assert(desc2);
|
|
assertEquals(typeof desc2!.get, "function");
|
|
|
|
assertEquals(desc1!.get, desc2!.get);
|
|
});
|