diff options
Diffstat (limited to 'js/timers_test.ts')
-rw-r--r-- | js/timers_test.ts | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/js/timers_test.ts b/js/timers_test.ts index 51dfbd7e0..7769be010 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -9,10 +9,12 @@ function deferred(): { } { let resolve; let reject; - const promise = new Promise((res, rej) => { - resolve = res; - reject = rej; - }); + const promise = new Promise( + (res, rej): void => { + resolve = res; + reject = rej; + } + ); return { promise, resolve, @@ -21,13 +23,13 @@ function deferred(): { } async function waitForMs(ms): Promise<number> { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise((resolve): number => setTimeout(resolve, ms)); } -test(async function timeoutSuccess() { +test(async function timeoutSuccess(): Promise<void> { const { promise, resolve } = deferred(); let count = 0; - setTimeout(() => { + setTimeout((): void => { count++; resolve(); }, 500); @@ -36,11 +38,11 @@ test(async function timeoutSuccess() { assertEquals(count, 1); }); -test(async function timeoutArgs() { +test(async function timeoutArgs(): Promise<void> { const { promise, resolve } = deferred(); const arg = 1; setTimeout( - (a, b, c) => { + (a, b, c): void => { assertEquals(a, arg); assertEquals(b, arg.toString()); assertEquals(c, [arg]); @@ -54,9 +56,9 @@ test(async function timeoutArgs() { await promise; }); -test(async function timeoutCancelSuccess() { +test(async function timeoutCancelSuccess(): Promise<void> { let count = 0; - const id = setTimeout(() => { + const id = setTimeout((): void => { count++; }, 1); // Cancelled, count should not increment @@ -65,7 +67,7 @@ test(async function timeoutCancelSuccess() { assertEquals(count, 0); }); -test(async function timeoutCancelMultiple() { +test(async function timeoutCancelMultiple(): Promise<void> { function uncalled(): never { throw new Error("This function should not be called."); } @@ -90,11 +92,11 @@ test(async function timeoutCancelMultiple() { await waitForMs(50); }); -test(async function timeoutCancelInvalidSilentFail() { +test(async function timeoutCancelInvalidSilentFail(): Promise<void> { // Expect no panic const { promise, resolve } = deferred(); let count = 0; - const id = setTimeout(() => { + const id = setTimeout((): void => { count++; // Should have no effect clearTimeout(id); @@ -107,10 +109,10 @@ test(async function timeoutCancelInvalidSilentFail() { clearTimeout(2147483647); }); -test(async function intervalSuccess() { +test(async function intervalSuccess(): Promise<void> { const { promise, resolve } = deferred(); let count = 0; - const id = setInterval(() => { + const id = setInterval((): void => { count++; clearInterval(id); resolve(); @@ -122,9 +124,9 @@ test(async function intervalSuccess() { assertEquals(count, 1); }); -test(async function intervalCancelSuccess() { +test(async function intervalCancelSuccess(): Promise<void> { let count = 0; - const id = setInterval(() => { + const id = setInterval((): void => { count++; }, 1); clearInterval(id); @@ -132,7 +134,7 @@ test(async function intervalCancelSuccess() { assertEquals(count, 0); }); -test(async function intervalOrdering() { +test(async function intervalOrdering(): Promise<void> { const timers = []; let timeouts = 0; function onTimeout(): void { @@ -148,14 +150,16 @@ test(async function intervalOrdering() { assertEquals(timeouts, 1); }); -test(async function intervalCancelInvalidSilentFail() { +test(async function intervalCancelInvalidSilentFail(): Promise<void> { // Should silently fail (no panic) clearInterval(2147483647); }); -test(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { +test(async function fireCallbackImmediatelyWhenDelayOverMaxValue(): Promise< + void +> { let count = 0; - setTimeout(() => { + setTimeout((): void => { count++; }, 2 ** 31); await waitForMs(1); |