diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/timers_test.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/js/timers_test.ts b/js/timers_test.ts index af172e976..6452697e0 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -1,3 +1,4 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. import { test, assertEqual } from "./test_util.ts"; function deferred() { @@ -30,6 +31,28 @@ test(async function timeoutSuccess() { assertEqual(count, 1); }); +test(async function timeoutArgs() { + let arg = 1; + await new Promise((resolve, reject) => { + setTimeout( + (a, b, c) => { + try { + assertEqual(a, arg); + assertEqual(b, arg.toString()); + assertEqual(c, [arg]); + resolve(); + } catch (e) { + reject(e); + } + }, + 10, + arg, + arg.toString(), + [arg] + ); + }); +}); + test(async function timeoutCancelSuccess() { let count = 0; const id = setTimeout(() => { @@ -91,6 +114,30 @@ test(async function intervalCancelSuccess() { assertEqual(count, 0); }); +test(async function intervalCancelSuccess2() { + const timers = []; + let timeouts = 0; + for (let i = 0; i < 5; i++) { + timers[i] = setTimeout(onTimeout, 20 * i); + } + function onTimeout() { + ++timeouts; + for (let i = 1; i < timers.length; i++) { + clearTimeout(timers[i]); + } + } + await new Promise((resolve, reject) => { + setTimeout(() => { + try { + assertEqual(timeouts, 1); + resolve(); + } catch (e) { + reject(e); + } + }, 200); + }); +}); + test(async function intervalCancelInvalidSilentFail() { // Should silently fail (no panic) clearInterval(2147483647); |