enzyme: dive() breaks when using the new context API.

Describe the bug

The new React context elements (https://reactjs.org/docs/context.html) report their type as objects instead of functions (custom react components) or strings (native react components), which breaks dive(). I haven’t tested whether other methods of ShallowWrapper break.

To Reproduce

https://codesandbox.io/s/zxj4898zxp?module=%2Fsrc%2FApp.test.js

Expected behavior

shallow and dive should implement actual render semantics when handling the new context API:

  1. Automatically update current context whenever a context provider is encountered and remove the provider node from the tree.
  2. Automatically pass the current context to childs of context consumer nodes and remove the consumer node from the tree.

I’m sure the above are not the exact semantics, but at least the most intuitive.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 38
  • Comments: 22 (9 by maintainers)

Most upvoted comments

I’ve just landed #1960, and rebased #1966 (which needs some more work). I’m hopeful to make a release soon.

@csvan the two pieces I’m waiting for are #1960 and then #1966; after those go in, I suspect it’ll be relatively short work to get full createContext support.

Is there a workaround for this issue? Getting this when testing redux connected components.

~Unless I’m missing something redux is only at 4.0.1. https://github.com/reduxjs/redux/releases~

Nvm. Assuming you meant react-redux. I should try that…

@alexandrudanpop downgrade to react-redux < 6, iirc.

Sorry, about that.

@paddotk it’s not been fixed yet.