Skip to content

Commit

Permalink
[Tests] add passing suspenseFallback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 21, 2020
1 parent 0e39e1f commit 2227326
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
memo,
Profiler,
Suspense,
useCallback,
} from './_helpers/react-compat';
import {
describeIf,
Expand Down Expand Up @@ -2031,6 +2032,46 @@ describe('shallow', () => {
});
});
});

// TODO: fix in v16.6 and v16.7
describeIf(is('>= 16.8'), 'avoids regressing #2200', () => {
const Home = lazy && lazy(() => new Promise(() => {}));

const PageSwitchFallback = memo ? memo(() => <div aria-live="polite" aria-busy />) : {};
PageSwitchFallback.displayName = 'PageSwitchFallback';

const PageSwitch = memo && memo(({ pageData }) => {
const renderPageComponent = useCallback ? useCallback(() => {
if (pageData === 'NOT_FOUND') return null;

switch (pageData.key) {
case 'home':
return <Home />;
default:
return null;
}
}, [pageData]) : () => {};

return (
<Suspense fallback={<PageSwitchFallback />}>
{renderPageComponent()}
</Suspense>
);
});
PageSwitch.displayName = 'PageSwitch';

it('works with suspenseFallback: true', () => {
const wrapper = shallow(<PageSwitch pageData={{ key: 'home' }} />, { suspenseFallback: true });
expect(wrapper.find(PageSwitchFallback)).to.have.lengthOf(1);
expect(wrapper.find(Home)).to.have.lengthOf(0);
});

it('works with suspenseFallback: false', () => {
const wrapper = shallow(<PageSwitch pageData={{ key: 'home' }} />, { suspenseFallback: false });
expect(wrapper.find(PageSwitchFallback)).to.have.lengthOf(0);
expect(wrapper.find(Home)).to.have.lengthOf(1);
});
});
});

describe('lifecycle methods', () => {
Expand Down

0 comments on commit 2227326

Please sign in to comment.