From 95e796fdb6d97144998818b9f7d585f542cf1001 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 14 Sep 2019 12:13:51 -0400 Subject: [PATCH] test: fix suspense tests in Node 12 --- .../__tests__/rendererSuspense.spec.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/__tests__/rendererSuspense.spec.ts b/packages/runtime-core/__tests__/rendererSuspense.spec.ts index 7068ab0a..47c7148c 100644 --- a/packages/runtime-core/__tests__/rendererSuspense.spec.ts +++ b/packages/runtime-core/__tests__/rendererSuspense.spec.ts @@ -26,11 +26,16 @@ describe('renderer: suspense', () => { delay: number = 0 ) { return { - async setup(props: any, { slots }: any) { - const p: Promise = new Promise(r => setTimeout(() => r(comp), delay)) - deps.push(p) - const Inner = await p - return () => h(Inner, props, slots) + setup(props: any, { slots }: any) { + const p = new Promise(resolve => { + setTimeout(() => { + resolve(() => h(comp, props, slots)) + }, delay) + }) + // in Node 12, due to timer/nextTick mechanism change, we have to wait + // an extra tick to avoid race conditions + deps.push(p.then(() => Promise.resolve())) + return p } } } @@ -98,13 +103,16 @@ describe('renderer: suspense', () => { const root = nodeOps.createElement('div') render(h(Comp), root) expect(serializeInner(root)).toBe(`
fallback
`) + expect(calls).toEqual([]) await deps[0] await nextTick() expect(serializeInner(root)).toBe(`
fallback
`) + expect(calls).toEqual([]) await Promise.all(deps) await nextTick() + expect(calls).toEqual([`outer mounted`, `inner mounted`]) expect(serializeInner(root)).toBe(`
inner
`) }) @@ -152,7 +160,8 @@ describe('renderer: suspense', () => { const Async = { async setup() { const p = new Promise(r => setTimeout(r, 1)) - deps.push(p) + // extra tick needed for Node 12+ + deps.push(p.then(() => Promise.resolve())) watch(() => { calls.push('watch callback')