@@ -884,27 +884,62 @@ function testRender(type: string, render: typeof renderToString) {
884
884
test ( 'multiple onServerPrefetch' , async ( ) => {
885
885
const msg = Promise . resolve ( 'hello' )
886
886
const msg2 = Promise . resolve ( 'hi' )
887
+ const msg3 = Promise . resolve ( 'bonjour' )
887
888
const app = createApp ( {
888
889
setup ( ) {
889
890
const message = ref ( '' )
890
891
const message2 = ref ( '' )
892
+ const message3 = ref ( '' )
891
893
onServerPrefetch ( async ( ) => {
892
894
message . value = await msg
893
895
} )
894
896
onServerPrefetch ( async ( ) => {
895
897
message2 . value = await msg2
896
898
} )
899
+ onServerPrefetch ( async ( ) => {
900
+ message3 . value = await msg3
901
+ } )
897
902
return {
898
903
message,
899
- message2
904
+ message2,
905
+ message3
900
906
}
901
907
} ,
902
908
render ( ) {
903
- return h ( 'div' , `${ this . message } ${ this . message2 } ` )
909
+ return h ( 'div' , `${ this . message } ${ this . message2 } ${ this . message3 } ` )
904
910
}
905
911
} )
906
912
const html = await render ( app )
907
- expect ( html ) . toBe ( `<div>hello hi</div>` )
913
+ expect ( html ) . toBe ( `<div>hello hi bonjour</div>` )
914
+ } )
915
+
916
+ test ( 'onServerPrefetch are run in parallel' , async ( ) => {
917
+ const first = jest . fn ( ( ) => Promise . resolve ( ) )
918
+ const second = jest . fn ( ( ) => Promise . resolve ( ) )
919
+ let checkOther = [ false , false ]
920
+ let done = [ false , false ]
921
+ const app = createApp ( {
922
+ setup ( ) {
923
+ onServerPrefetch ( async ( ) => {
924
+ checkOther [ 0 ] = done [ 1 ]
925
+ await first ( )
926
+ done [ 0 ] = true
927
+ } )
928
+ onServerPrefetch ( async ( ) => {
929
+ checkOther [ 1 ] = done [ 0 ]
930
+ await second ( )
931
+ done [ 1 ] = true
932
+ } )
933
+ } ,
934
+ render ( ) {
935
+ return h ( 'div' , '' )
936
+ }
937
+ } )
938
+ await render ( app )
939
+ expect ( first ) . toHaveBeenCalled ( )
940
+ expect ( second ) . toHaveBeenCalled ( )
941
+ expect ( checkOther ) . toEqual ( [ false , false ] )
942
+ expect ( done ) . toEqual ( [ true , true ] )
908
943
} )
909
944
} )
910
945
}
0 commit comments