]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: add test case edison/fix/4930 12082/head
authordaiwei <daiwei521@126.com>
Mon, 30 Sep 2024 03:03:48 +0000 (11:03 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 30 Sep 2024 03:03:48 +0000 (11:03 +0800)
packages/runtime-core/__tests__/rendererTemplateRef.spec.ts

index 799108dca8ae3829c7b8457d9b18e02b626c415f..62aebd1a9951dd1efc869d00e614cbb1fc266f37 100644 (file)
@@ -1,4 +1,5 @@
 import {
+  Suspense,
   defineComponent,
   h,
   nextTick,
@@ -537,4 +538,39 @@ describe('api: template refs', () => {
       '<div><div>[object Object],[object Object]</div><ul><li>2</li><li>3</li></ul></div>',
     )
   })
+
+  it('with async component', async () => {
+    const deps: Promise<any>[] = []
+    const spy = vi.fn()
+
+    const AsyncChild = defineComponent({
+      async setup(_, { expose }) {
+        const p = new Promise(r => setTimeout(r, 1))
+        deps.push(p.then(() => Promise.resolve()))
+        await p
+        expose({ foo: spy })
+        return () => h('div', 'child')
+      },
+    })
+
+    const childRef = ref(null)
+    const App = {
+      setup() {
+        return { refKey: childRef }
+      },
+      render() {
+        return h(Suspense, null, { default: h(AsyncChild, { ref: 'refKey' }) })
+      },
+    }
+
+    const root = nodeOps.createElement('div')
+    render(h(App), root)
+
+    await Promise.all(deps)
+    await nextTick()
+
+    expect((childRef.value as any).foo).toBe(spy)
+    ;(childRef.value as any).foo()
+    expect(spy).toBeCalledTimes(1)
+  })
 })