Skip to content

Commit 8932f3f

Browse files
committed
test: add tests
1 parent 5966fec commit 8932f3f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

packages/runtime-core/__tests__/components/Suspense.spec.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
onUnmounted,
1818
ref,
1919
render,
20+
renderList,
21+
renderSlot,
2022
resolveDynamicComponent,
2123
serializeInner,
2224
shallowRef,
@@ -2161,6 +2163,82 @@ describe('Suspense', () => {
21612163
await Promise.all(deps)
21622164
})
21632165

2166+
// #13453
2167+
test('add new async deps during patching', async () => {
2168+
const getComponent = (type: string) => {
2169+
if (type === 'A') {
2170+
return defineAsyncComponent({
2171+
name: 'A',
2172+
setup() {
2173+
return () => h('div', 'A')
2174+
},
2175+
})
2176+
}
2177+
return defineAsyncComponent({
2178+
name: 'A',
2179+
setup() {
2180+
return () => h('div', 'B')
2181+
},
2182+
})
2183+
}
2184+
2185+
const types = ref(['A'])
2186+
const add = async () => {
2187+
types.value.push('B')
2188+
}
2189+
2190+
const update = async () => {
2191+
// mount Suspense B
2192+
// [Suspense A] -> [Suspense A(pending), Suspense B(pending)]
2193+
await add()
2194+
// patch Suspense B (still pending)
2195+
// [Suspense A(pending), Suspense B(pending)] -> [Suspense B(pending)]
2196+
types.value.shift()
2197+
}
2198+
2199+
const Comp = {
2200+
render(this: any) {
2201+
return h(Fragment, null, [
2202+
renderList(types.value, type => {
2203+
return h(
2204+
Suspense,
2205+
{ key: type },
2206+
{
2207+
default: () => [
2208+
renderSlot(this.$slots, 'default', { type: type }),
2209+
],
2210+
},
2211+
)
2212+
}),
2213+
])
2214+
},
2215+
}
2216+
2217+
const App = {
2218+
setup() {
2219+
return () =>
2220+
h(Comp, null, {
2221+
default: (params: any) => [h(getComponent(params.type))],
2222+
})
2223+
},
2224+
}
2225+
2226+
const root = nodeOps.createElement('div')
2227+
render(h(App), root)
2228+
expect(serializeInner(root)).toBe(`<!---->`)
2229+
2230+
await Promise.all(deps)
2231+
expect(serializeInner(root)).toBe(`<div>A</div>`)
2232+
2233+
update()
2234+
await nextTick()
2235+
// wait for both A and B to resolve
2236+
await Promise.all(deps)
2237+
// wait for new B to resolve
2238+
await Promise.all(deps)
2239+
expect(serializeInner(root)).toBe(`<div>B</div>`)
2240+
})
2241+
21642242
describe('warnings', () => {
21652243
// base function to check if a combination of slots warns or not
21662244
function baseCheckWarn(

0 commit comments

Comments
 (0)