From 2227326a9d70ea8973337ea2e5ba66ab9b89253e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Dec 2020 22:29:14 -0800 Subject: [PATCH] [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 --- .../test/ShallowWrapper-spec.jsx | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx index 9411f1d56..abc064bfc 100644 --- a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx @@ -28,6 +28,7 @@ import { memo, Profiler, Suspense, + useCallback, } from './_helpers/react-compat'; import { describeIf, @@ -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(() =>
) : {}; + PageSwitchFallback.displayName = 'PageSwitchFallback'; + + const PageSwitch = memo && memo(({ pageData }) => { + const renderPageComponent = useCallback ? useCallback(() => { + if (pageData === 'NOT_FOUND') return null; + + switch (pageData.key) { + case 'home': + return ; + default: + return null; + } + }, [pageData]) : () => {}; + + return ( + }> + {renderPageComponent()} + + ); + }); + PageSwitch.displayName = 'PageSwitch'; + + it('works with suspenseFallback: true', () => { + const wrapper = shallow(, { 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(, { suspenseFallback: false }); + expect(wrapper.find(PageSwitchFallback)).to.have.lengthOf(0); + expect(wrapper.find(Home)).to.have.lengthOf(1); + }); + }); }); describe('lifecycle methods', () => {