diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2021-08-25 16:04:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 16:04:14 -0400 |
commit | 5d7d9d64434bd0a9f1fcf391dabc51693e8cf1ae (patch) | |
tree | c217fac5a7d67ba326d456b2973d23a7c7b151d4 /cli/tests/unit/timers_test.ts | |
parent | 66476efec5b92cd04c161d82cbb69992fed4eb0a (diff) |
chore(tests): improve unit tests using `deferred` (#11842)
Diffstat (limited to 'cli/tests/unit/timers_test.ts')
-rw-r--r-- | cli/tests/unit/timers_test.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts index 4eb470ba9..2decddbd9 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -86,11 +86,10 @@ unitTest(async function timeoutEvalNoScopeLeak() { unitTest(async function timeoutArgs() { const promise = deferred(); const arg = 1; + let capturedArgs: unknown[] = []; setTimeout( - (a, b, c) => { - assertEquals(a, arg); - assertEquals(b, arg.toString()); - assertEquals(c, [arg]); + function () { + capturedArgs = [...arguments]; promise.resolve(); }, 10, @@ -99,6 +98,11 @@ unitTest(async function timeoutArgs() { [arg], ); await promise; + assertEquals(capturedArgs, [ + arg, + arg.toString(), + [arg], + ]); }); unitTest(async function timeoutCancelSuccess() { @@ -214,14 +218,16 @@ unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { unitTest(async function timeoutCallbackThis() { const promise = deferred(); + let capturedThis: unknown; const obj = { foo() { - assertEquals(this, window); + capturedThis = this; promise.resolve(); }, }; setTimeout(obj.foo, 1); await promise; + assertEquals(capturedThis, window); }); unitTest(async function timeoutBindThis() { |