Skip to content

ShallowWrapper::dive fails when diving into a memoized component inside a context provider #2290

@moward

Description

@moward

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions