summaryrefslogtreecommitdiff
path: root/cli/tests/unit/timers_test.ts
diff options
context:
space:
mode:
authorKyle June <kylejune1415@gmail.com>2020-07-04 15:16:27 -0400
committerGitHub <noreply@github.com>2020-07-04 15:16:27 -0400
commitd52e4007c887caaa073e43088fd92c3589a41dd5 (patch)
treebc8696eaff52eaddb84b5f2b7f3cc285c8b4a888 /cli/tests/unit/timers_test.ts
parent5f9e600c5bb78ae35a9a12d250f1d7cad79cf7a4 (diff)
Update timers to ignore Date Override (#6552)
Diffstat (limited to 'cli/tests/unit/timers_test.ts')
-rw-r--r--cli/tests/unit/timers_test.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts
index 7adff0095..8a22173de 100644
--- a/cli/tests/unit/timers_test.ts
+++ b/cli/tests/unit/timers_test.ts
@@ -366,3 +366,37 @@ unitTest(async function timerNestedMicrotaskOrdering(): Promise<void> {
unitTest(function testQueueMicrotask() {
assertEquals(typeof queueMicrotask, "function");
});
+
+unitTest(async function timerIgnoresDateOverride(): Promise<void> {
+ const OriginalDate = Date;
+ const { promise, resolve, reject } = deferred();
+ let hasThrown = 0;
+ try {
+ const overrideCalled: () => number = () => {
+ reject("global Date override used over original Date object");
+ return 0;
+ };
+ function DateOverride(): void {
+ overrideCalled();
+ }
+ globalThis.Date = DateOverride as DateConstructor;
+ globalThis.Date.now = overrideCalled;
+ globalThis.Date.UTC = overrideCalled;
+ globalThis.Date.parse = overrideCalled;
+ queueMicrotask(resolve);
+ await promise;
+ hasThrown = 1;
+ } catch (err) {
+ if (typeof err === "string") {
+ assertEquals(err, "global Date override used over original Date object");
+ hasThrown = 2;
+ } else if (err instanceof TypeError) {
+ hasThrown = 3;
+ } else {
+ hasThrown = 4;
+ }
+ } finally {
+ globalThis.Date = OriginalDate;
+ }
+ assertEquals(hasThrown, 1);
+});