@@ -12,10 +12,11 @@ import {
12
12
} from 'vue'
13
13
import { renderToString } from '@vue/server-renderer'
14
14
15
- type TestCaseFactory = ( ) => [ App , Promise < any > [ ] ]
15
+ type FactoryRes = [ App , Promise < any > [ ] ]
16
+ type TestCaseFactory = ( ) => FactoryRes | Promise < FactoryRes >
16
17
17
18
async function runOnClient ( factory : TestCaseFactory ) {
18
- const [ app , deps ] = factory ( )
19
+ const [ app , deps ] = await factory ( )
19
20
const root = document . createElement ( 'div' )
20
21
app . mount ( root )
21
22
await Promise . all ( deps )
@@ -24,7 +25,7 @@ async function runOnClient(factory: TestCaseFactory) {
24
25
}
25
26
26
27
async function runOnServer ( factory : TestCaseFactory ) {
27
- const [ app , _ ] = factory ( )
28
+ const [ app , _ ] = await factory ( )
28
29
return ( await renderToString ( app ) )
29
30
. replace ( / < ! - - [ \[ \] ] - - > / g, '' ) // remove fragment wrappers
30
31
. trim ( )
@@ -240,11 +241,11 @@ describe('useId', () => {
240
241
expect ( await getOutput ( ( ) => factory ( ) ) ) . toBe ( expected )
241
242
} )
242
243
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 (
245
246
delay1 : number ,
246
247
delay2 : number ,
247
- ) : ReturnType < TestCaseFactory > => {
248
+ ) : Promise < FactoryRes > => {
248
249
const p1 = promiseWithDelay ( null , delay1 )
249
250
const p2 = promiseWithDelay ( BasicComponentWithUseId , delay2 )
250
251
const AsyncInner = defineAsyncComponent ( ( ) => p2 )
@@ -269,6 +270,9 @@ describe('useId', () => {
269
270
} )
270
271
} ,
271
272
} )
273
+
274
+ // the async component may have already been resolved
275
+ await AsyncInner . __asyncLoader ( )
272
276
return [ app , [ p1 , p2 ] ]
273
277
}
274
278
@@ -278,7 +282,7 @@ describe('useId', () => {
278
282
'v:0-0-0 v:0-0-1' + // async component inside async setup
279
283
'</div>'
280
284
// 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 )
282
286
expect ( await getOutput ( ( ) => factory ( 16 , 0 ) ) ) . toBe ( expected )
283
287
} )
284
288
} )
0 commit comments