@@ -28,6 +28,7 @@ import {
28
28
memo ,
29
29
Profiler ,
30
30
Suspense ,
31
+ useCallback ,
31
32
} from './_helpers/react-compat' ;
32
33
import {
33
34
describeIf ,
@@ -2031,6 +2032,46 @@ describe('shallow', () => {
2031
2032
} ) ;
2032
2033
} ) ;
2033
2034
} ) ;
2035
+
2036
+ // TODO: fix in v16.6 and v16.7
2037
+ describeIf ( is ( '>= 16.8' ) , 'avoids regressing #2200' , ( ) => {
2038
+ const Home = lazy && lazy ( ( ) => new Promise ( ( ) => { } ) ) ;
2039
+
2040
+ const PageSwitchFallback = memo ? memo ( ( ) => < div aria-live = "polite" aria-busy /> ) : { } ;
2041
+ PageSwitchFallback . displayName = 'PageSwitchFallback' ;
2042
+
2043
+ const PageSwitch = memo && memo ( ( { pageData } ) => {
2044
+ const renderPageComponent = useCallback ? useCallback ( ( ) => {
2045
+ if ( pageData === 'NOT_FOUND' ) return null ;
2046
+
2047
+ switch ( pageData . key ) {
2048
+ case 'home' :
2049
+ return < Home /> ;
2050
+ default :
2051
+ return null ;
2052
+ }
2053
+ } , [ pageData ] ) : ( ) => { } ;
2054
+
2055
+ return (
2056
+ < Suspense fallback = { < PageSwitchFallback /> } >
2057
+ { renderPageComponent ( ) }
2058
+ </ Suspense >
2059
+ ) ;
2060
+ } ) ;
2061
+ PageSwitch . displayName = 'PageSwitch' ;
2062
+
2063
+ it ( 'works with suspenseFallback: true' , ( ) => {
2064
+ const wrapper = shallow ( < PageSwitch pageData = { { key : 'home' } } /> , { suspenseFallback : true } ) ;
2065
+ expect ( wrapper . find ( PageSwitchFallback ) ) . to . have . lengthOf ( 1 ) ;
2066
+ expect ( wrapper . find ( Home ) ) . to . have . lengthOf ( 0 ) ;
2067
+ } ) ;
2068
+
2069
+ it ( 'works with suspenseFallback: false' , ( ) => {
2070
+ const wrapper = shallow ( < PageSwitch pageData = { { key : 'home' } } /> , { suspenseFallback : false } ) ;
2071
+ expect ( wrapper . find ( PageSwitchFallback ) ) . to . have . lengthOf ( 0 ) ;
2072
+ expect ( wrapper . find ( Home ) ) . to . have . lengthOf ( 1 ) ;
2073
+ } ) ;
2074
+ } ) ;
2034
2075
} ) ;
2035
2076
2036
2077
describe ( 'lifecycle methods' , ( ) => {
0 commit comments