-
-
Notifications
You must be signed in to change notification settings - Fork 2k
ShallowWrapper::dive fails when diving into a memoized component inside a context provider #2290
Copy link
Copy link
Closed
Description
Current behavior
Calling
const SampleContextA = React.createContext<T>(true);
const MyComponent = () => <div />;
const MyComponentMemoized = React.memo(MyComponent);
enzyme
.shallow(
<SampleContextA.Provider value={false}>
<MyComponentMemoized />
</SampleContextA.Provider>
)
.dive();throws with TypeError: ShallowWrapper::dive() can only be called on components. If you replace the provider wrapper with just a plain wrapper, e.g.
const Wrapper = (props) => React.Children.only(props.children);it renders fine. It also works fine in you use MyComponent unmemoized.
Expected behavior
This code should return a ShallowWrapper to the contents of <MyComponent /> instead of throwing.
Your environment
API
- shallow
- mount
- render
Version
| library | version |
|---|---|
| enzyme | 3.10.0 |
| react | 16.12.0 |
| react-dom | 16.12.0 |
| react-test-renderer | 16.12.0 |
| adapter (below) | 1.15.1 |
Adapter
- enzyme-adapter-react-16
- others ( )
Notes
I believe this is similar to but distinct from #2103. That issue addressed memoized components being wrapped by regular custom components.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels