Skip to content

Commit

Permalink
[enzyme-adapter-react-16] [fix] avoid a crash with lazy components
Browse files Browse the repository at this point in the history
Fixes #2539
  • Loading branch information
ljharb committed Sep 17, 2021
1 parent 58d61d3 commit 49bc86b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function findCurrentFiberUsingSlowPath(fiber) {
}
}
}
if (a.stateNode.current === a) {
if (a.stateNode?.current === a) {
// We've determined that A is the current branch.
return fiber;
}
Expand Down
34 changes: 34 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
memo,
Profiler,
Suspense,
useState,
useEffect,
} from './_helpers/react-compat';
import {
describeWithDOM,
Expand Down Expand Up @@ -1285,6 +1287,38 @@ describeWithDOM('mount', () => {
);
expect(() => mount(<SuspenseComponent />, { suspenseFallback: false })).to.throw();
});

it('avoids a TypeError', () => {
const Component2 = lazy(() => Promise.resolve({ default: () => <div /> }));

function Component() {
const [alreadyRun, setAlreadyRun] = useState(false);

useEffect(() => {
setAlreadyRun(true);
}, []);

if (!alreadyRun) {
return null;
}

return <Component2 />;
}

const wrapper = mount(
<Suspense fallback={<div>loading</div>}>
<Component />
</Suspense>,
);
expect(wrapper.debug()).to.equal(
`<Suspense fallback={{...}}>
<Component />
<div>
loading
</div>
</Suspense>`,
);
});
});

describe('.mount()', () => {
Expand Down

0 comments on commit 49bc86b

Please sign in to comment.