From 951e5def9856ee15be52c153a1d2cb7dd73f0da8 Mon Sep 17 00:00:00 2001 From: Li Hao Date: Mon, 8 Oct 2018 14:58:44 +0800 Subject: timers: align unit tests with others --- js/timers_test.ts | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'js/timers_test.ts') diff --git a/js/timers_test.ts b/js/timers_test.ts index 8d5245f11..78f6610c4 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -32,25 +32,21 @@ test(async function timeoutSuccess() { }); test(async function timeoutArgs() { + const { promise, resolve } = deferred(); const 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] - ); - }); + setTimeout( + (a, b, c) => { + assertEqual(a, arg); + assertEqual(b, arg.toString()); + assertEqual(c, [arg]); + resolve(); + }, + 10, + arg, + arg.toString(), + [arg] + ); + await promise; }); test(async function timeoutCancelSuccess() { @@ -151,16 +147,8 @@ test(async function intervalOrdering() { clearTimeout(timers[i]); } } - await new Promise((resolve, reject) => { - setTimeout(() => { - try { - assertEqual(timeouts, 1); - resolve(); - } catch (e) { - reject(e); - } - }, 100); - }); + await waitForMs(100); + assertEqual(timeouts, 1); }); test(async function intervalCancelInvalidSilentFail() { -- cgit v1.2.3