diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-26 22:58:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 23:58:28 +0200 |
commit | ba58628601057c6f996cbad287fcfbe353872368 (patch) | |
tree | 5642806d3aed1d46eab233511ef8a929cf0c51d3 /tests/unit/timers_test.ts | |
parent | 631d931973fbb7d2e01e1aeb87a33dd9d63ec38e (diff) |
Reland "test: run unit tests with DENO_FUTURE=1" (#25212)
Reverted in https://github.com/denoland/deno/pull/25060
Diffstat (limited to 'tests/unit/timers_test.ts')
-rw-r--r-- | tests/unit/timers_test.ts | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/tests/unit/timers_test.ts b/tests/unit/timers_test.ts index 70619ae35..212f197cc 100644 --- a/tests/unit/timers_test.ts +++ b/tests/unit/timers_test.ts @@ -7,6 +7,7 @@ import { assertEquals, assertNotEquals, delay, + DENO_FUTURE, execCode, unreachable, } from "./test_util.ts"; @@ -311,11 +312,63 @@ Deno.test(async function timeoutCallbackThis() { }; setTimeout(obj.foo, 1); await promise; - assertEquals(capturedThis, window); + if (!DENO_FUTURE) { + assertEquals(capturedThis, window); + } else { + assertEquals(capturedThis, globalThis); + } +}); + +Deno.test({ ignore: DENO_FUTURE }, async function timeoutBindThis() { + const thisCheckPassed = [null, undefined, globalThis, window]; + + const thisCheckFailed = [ + 0, + "", + true, + false, + {}, + [], + "foo", + () => {}, + Object.prototype, + ]; + + for (const thisArg of thisCheckPassed) { + const { promise, resolve } = Promise.withResolvers<void>(); + let hasThrown = 0; + try { + setTimeout.call(thisArg, () => resolve(), 1); + hasThrown = 1; + } catch (err) { + if (err instanceof TypeError) { + hasThrown = 2; + } else { + hasThrown = 3; + } + } + await promise; + assertEquals(hasThrown, 1); + } + + for (const thisArg of thisCheckFailed) { + let hasThrown = 0; + try { + setTimeout.call(thisArg, () => {}, 1); + hasThrown = 1; + } catch (err) { + if (err instanceof TypeError) { + hasThrown = 2; + } else { + hasThrown = 3; + } + } + assertEquals(hasThrown, 2); + } }); -Deno.test(async function timeoutBindThis() { - const thisCheckPassed = [null, undefined, window, globalThis]; +Deno.test({ ignore: !DENO_FUTURE }, async function timeoutBindThis() { + const thisCheckPassed = [null, undefined, globalThis]; const thisCheckFailed = [ 0, |