From cb11c0118c5d86290dd89caf0e2ee6c49ed4e8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 20 Nov 2019 15:13:55 +0100 Subject: [PATCH] [FIX] context tests: make them deterministic We learn something new every day, and today is no exception. Promise.all of a pending promise does not actually resolve as fast as possible after the initial promise is completed, but a small delay after, because it is put on the macrotask queue or something like that (I assume) closes #480 --- tests/context.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/context.test.ts b/tests/context.test.ts index 5be3b1de..52802ab1 100644 --- a/tests/context.test.ts +++ b/tests/context.test.ts @@ -106,7 +106,7 @@ describe("Context", () => { expect(fixture.innerHTML).toBe("
321321
"); }); - test("two async components on two levels are updated in parallel", async () => { + test("two async components on two levels are updated (mostly) in parallel", async () => { const testContext = new Context({ value: 123 }); const def = makeDeferred(); const steps: string[] = []; @@ -151,6 +151,11 @@ describe("Context", () => { ); def.resolve(); await nextTick(); + // we need to wait for an extra tick because it could happen (even though it + // is rare) that the second batch of renderings is not done yet, because + // the initial promise has been given to the macrotask queue, so a small + // delay happens. + await nextTick(); expect(steps).toEqual(["render", "render", "render"]); expect(fixture.innerHTML).toBe( "

321

321

321

"