@@ -740,27 +740,62 @@ function testRender(type: string, render: typeof renderToString) {
740
740
test ( 'multiple onServerPrefetch' , async ( ) => {
741
741
const msg = Promise . resolve ( 'hello' )
742
742
const msg2 = Promise . resolve ( 'hi' )
743
+ const msg3 = Promise . resolve ( 'bonjour' )
743
744
const app = createApp ( {
744
745
setup ( ) {
745
746
const message = ref ( '' )
746
747
const message2 = ref ( '' )
748
+ const message3 = ref ( '' )
747
749
onServerPrefetch ( async ( ) => {
748
750
message . value = await msg
749
751
} )
750
752
onServerPrefetch ( async ( ) => {
751
753
message2 . value = await msg2
752
754
} )
755
+ onServerPrefetch ( async ( ) => {
756
+ message3 . value = await msg3
757
+ } )
753
758
return {
754
759
message,
755
- message2
760
+ message2,
761
+ message3
756
762
}
757
763
} ,
758
764
render ( ) {
759
- return h ( 'div' , `${ this . message } ${ this . message2 } ` )
765
+ return h ( 'div' , `${ this . message } ${ this . message2 } ${ this . message3 } ` )
760
766
}
761
767
} )
762
768
const html = await render ( app )
763
- expect ( html ) . toBe ( `<div>hello hi</div>` )
769
+ expect ( html ) . toBe ( `<div>hello hi bonjour</div>` )
770
+ } )
771
+
772
+ test ( 'onServerPrefetch are run in parallel' , async ( ) => {
773
+ const first = jest . fn ( ( ) => Promise . resolve ( ) )
774
+ const second = jest . fn ( ( ) => Promise . resolve ( ) )
775
+ let checkOther = [ false , false ]
776
+ let done = [ false , false ]
777
+ const app = createApp ( {
778
+ setup ( ) {
779
+ onServerPrefetch ( async ( ) => {
780
+ checkOther [ 0 ] = done [ 1 ]
781
+ await first ( )
782
+ done [ 0 ] = true
783
+ } )
784
+ onServerPrefetch ( async ( ) => {
785
+ checkOther [ 1 ] = done [ 0 ]
786
+ await second ( )
787
+ done [ 1 ] = true
788
+ } )
789
+ } ,
790
+ render ( ) {
791
+ return h ( 'div' , '' )
792
+ }
793
+ } )
794
+ await render ( app )
795
+ expect ( first ) . toHaveBeenCalled ( )
796
+ expect ( second ) . toHaveBeenCalled ( )
797
+ expect ( checkOther ) . toEqual ( [ false , false ] )
798
+ expect ( done ) . toEqual ( [ true , true ] )
764
799
} )
765
800
} )
766
801
}
0 commit comments