Skip to content

Commit 2227326

Browse files
committed
[Tests] add passing suspenseFallback tests
See #2200 (comment)
1 parent 0e39e1f commit 2227326

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

+41
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
memo,
2929
Profiler,
3030
Suspense,
31+
useCallback,
3132
} from './_helpers/react-compat';
3233
import {
3334
describeIf,
@@ -2031,6 +2032,46 @@ describe('shallow', () => {
20312032
});
20322033
});
20332034
});
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+
});
20342075
});
20352076

20362077
describe('lifecycle methods', () => {

0 commit comments

Comments
 (0)