diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-14 21:50:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 22:50:06 +0200 |
commit | 22a834ff5b4b312b8f91be8991f2b495d49fad2f (patch) | |
tree | 66ed83a0898396a950c040aa70192bda95f9102e /tests/unit/timers_test.ts | |
parent | f89b5311492377a3ac18d756dc8c8a309e2c9e8a (diff) |
test: run unit tests with DENO_FUTURE=1 (#24400)
This commit adds another test suite that runs all Deno unit tests
with `DENO_FUTURE=1` flag to ensure all APIs are working as
expected, once Deno 2 is released.
---------
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
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 6e829c07f..679e57df7 100644 --- a/tests/unit/timers_test.ts +++ b/tests/unit/timers_test.ts @@ -4,6 +4,7 @@ import { assertEquals, assertNotEquals, delay, + DENO_FUTURE, execCode, unreachable, } from "./test_util.ts"; @@ -308,11 +309,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, |