Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow API setContext should work without static contextTypes for React 16 #1913

Open
2 of 13 tasks
eugef opened this issue Nov 22, 2018 · 4 comments
Open
2 of 13 tasks
Projects

Comments

@eugef
Copy link

eugef commented Nov 22, 2018

According to the latest React documentation static contextTypes is no more needed for Context API to work - only static contextType (single form here) is needed https://reactjs.org/docs/context.html#classcontexttype

Current behavior

Enzyme for React 16 still requires static contextTypes to be defined to make setContext() work.

Expected behavior

Enzyme for React 16 should only rely on static contextType.

Your environment

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.7.0
react 16.6.1
react-dom 16.6.3
react-test-renderer ---
adapter (below)

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Nov 22, 2018

enzyme doesn't yet support createContext at all (nor contextType) - see #1553.

@ljharb ljharb added this to Needs Triage in React 16 via automation Nov 22, 2018
@eugef
Copy link
Author

eugef commented Nov 22, 2018

Ok, got it

@mprobber
Copy link

Just wanted to plug facebook/react#14329 - I put a PR out for the shallow react-test-renderer so that when contextType is defined, you can just pass it a context. I could be wrong, but once that's merged + released, enzyme should be able to bump the version, and context should work on render.

@mjancarik
Copy link

I need working solution for static contextType. I didn't find how should be work with dive or wrappingComponent for PR so I created module for workaround https://www.npmjs.com/package/shallow-with-context. The module works well in our projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
React 16
  
Context
Development

No branches or pull requests

4 participants