File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -888,6 +888,45 @@ describe('Router', () => {
888
888
pushState . restore ( ) ;
889
889
replaceState . restore ( ) ;
890
890
} ) ;
891
+
892
+ it ( 'should support using `Router` as an implicit suspense boundary' , async ( ) => {
893
+ let data ;
894
+ function useSuspense ( ) {
895
+ const [ _ , update ] = useState ( ) ;
896
+
897
+ if ( ! data ) {
898
+ data = new Promise ( r => setTimeout ( r , 5 , 'data' ) ) ;
899
+ data . then (
900
+ ( res ) => update ( ( data . res = res ) ) ,
901
+ ( err ) => update ( ( data . err = err ) )
902
+ ) ;
903
+ }
904
+
905
+ if ( data . res ) return data . res ;
906
+ if ( data . err ) throw data . err ;
907
+ throw data ;
908
+ }
909
+
910
+ render (
911
+ < LocationProvider >
912
+ < Router >
913
+ < Route
914
+ path = "/"
915
+ component = { ( ) => {
916
+ const result = useSuspense ( ) ;
917
+ return < h1 > { result } </ h1 > ;
918
+ } }
919
+ />
920
+ </ Router >
921
+ < ShallowLocation />
922
+ </ LocationProvider > ,
923
+ scratch
924
+ ) ;
925
+
926
+ expect ( scratch ) . to . have . property ( 'textContent' , '' ) ;
927
+ await sleep ( 10 ) ;
928
+ expect ( scratch ) . to . have . property ( 'textContent' , 'data' ) ;
929
+ } ) ;
891
930
} ) ;
892
931
893
932
const MODE_HYDRATE = 1 << 5 ;
You can’t perform that action at this time.
0 commit comments