diff options
author | Li Hao <hao.x.li@intel.com> | 2018-09-05 13:35:29 +0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2018-10-03 13:27:59 -0700 |
commit | 99e2c42d16dc725a85ca22ee7e53e1387342a94c (patch) | |
tree | 499bf25501af89ee4506364850ac8659a5543ab6 | |
parent | aa691ea26c5dc8fd15b3b60b95a2c23b4888c45d (diff) |
timers: add some more unit tests
Closes #682.
-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); |