From 5121d183a116369510c1f79fb3b5accbeb6cb7a9 Mon Sep 17 00:00:00 2001 From: Alan Darmasaputra Date: Wed, 24 Jan 2024 14:07:06 +0700 Subject: [PATCH] tweak test code of actual --- machine-runner/tests/esm/runner.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/machine-runner/tests/esm/runner.test.ts b/machine-runner/tests/esm/runner.test.ts index 9780534..1927af9 100644 --- a/machine-runner/tests/esm/runner.test.ts +++ b/machine-runner/tests/esm/runner.test.ts @@ -611,6 +611,18 @@ describe('machine as async generator', () => { let resolved = false const actualPromise = machine.actual() actualPromise.finally(() => (resolved = true)) + + // ensures that the above actualPrimomise.finally callback is executed + // immediately IF actualPromise is a resolved promise this guarantee is + // enforced by this specification + // https://tc39.es/ecma262/multipage/executable-code-and-execution-contexts.html#sec-hostenqueuepromisejob + // saying that reactions (then, catch, finally callbacks) are executed in + // the order they are registered and since the await below is registered + // after the actualPromise.finally callback, the control flow will + // continue also after the finally callback is executed, which is + // important because the line below inspect the value of `resolved` + await Promise.resolve() + expect(resolved).toBe(false) await r1.toggleCommandDelay({ delaying: false, reject: true })