@@ -12,10 +12,11 @@ import {
1212} from 'vue'
1313import { renderToString } from '@vue/server-renderer'
1414
15- type TestCaseFactory = ( ) => [ App , Promise < any > [ ] ]
15+ type FactoryRes = [ App , Promise < any > [ ] ]
16+ type TestCaseFactory = ( ) => FactoryRes | Promise < FactoryRes >
1617
1718async function runOnClient ( factory : TestCaseFactory ) {
18- const [ app , deps ] = factory ( )
19+ const [ app , deps ] = await factory ( )
1920 const root = document . createElement ( 'div' )
2021 app . mount ( root )
2122 await Promise . all ( deps )
@@ -24,7 +25,7 @@ async function runOnClient(factory: TestCaseFactory) {
2425}
2526
2627async function runOnServer ( factory : TestCaseFactory ) {
27- const [ app , _ ] = factory ( )
28+ const [ app , _ ] = await factory ( )
2829 return ( await renderToString ( app ) )
2930 . replace ( / < ! - - [ \[ \] ] - - > / g, '' ) // remove fragment wrappers
3031 . trim ( )
@@ -240,11 +241,11 @@ describe('useId', () => {
240241 expect ( await getOutput ( ( ) => factory ( ) ) ) . toBe ( expected )
241242 } )
242243
243- test ( 'async component inside async setup' , async ( ) => {
244- const factory = (
244+ test ( 'async component inside async setup, already resolved ' , async ( ) => {
245+ const factory = async (
245246 delay1 : number ,
246247 delay2 : number ,
247- ) : ReturnType < TestCaseFactory > => {
248+ ) : Promise < FactoryRes > => {
248249 const p1 = promiseWithDelay ( null , delay1 )
249250 const p2 = promiseWithDelay ( BasicComponentWithUseId , delay2 )
250251 const AsyncInner = defineAsyncComponent ( ( ) => p2 )
@@ -269,6 +270,9 @@ describe('useId', () => {
269270 } )
270271 } ,
271272 } )
273+
274+ // the async component may have already been resolved
275+ await AsyncInner . __asyncLoader ( )
272276 return [ app , [ p1 , p2 ] ]
273277 }
274278
@@ -278,7 +282,7 @@ describe('useId', () => {
278282 'v:0-0-0 v:0-0-1' + // async component inside async setup
279283 '</div>'
280284 // assert different async resolution order does not affect id stable-ness
281- expect ( await getOutput ( ( ) => factory ( 0 , 16 ) ) ) . toBe ( expected )
285+ expect ( await getOutput ( async ( ) => factory ( 0 , 16 ) ) ) . toBe ( expected )
282286 expect ( await getOutput ( ( ) => factory ( 16 , 0 ) ) ) . toBe ( expected )
283287 } )
284288} )
0 commit comments