Allow .contextType on class based components#100
Allow .contextType on class based components#100unverbraucht wants to merge 2 commits intoenzymejs:masterfrom
Conversation
There was a problem hiding this comment.
@unverbraucht shouldn't it be checking for elementType.contextType instead of element.contextType?
Added line-specific comment
src/ReactShallowRenderer.js
Outdated
| this._rendering = true; | ||
| this._element = element; | ||
| this._context = getMaskedContext(elementType.contextTypes, context); | ||
| this._context = element.contextType |
There was a problem hiding this comment.
@unverbraucht shouldn't it be checking for elementType.contextType instead of element.contextType?
There was a problem hiding this comment.
I'm not sure, the approach in the PR worked for me. I'm afraid I can't test it anymore, we moved away from react-shallow-renderer completely on the project.
There was a problem hiding this comment.
Fair point if you've already moved on, which is what I'm already planning to do. However, I just confirmed that, while element.contextType is not defined, elementType.contextType is. Hopefully this little tidbit will help someone, even if this PR is never updated and merged.
There was a problem hiding this comment.
@ljharb I'm willing to update this PR since it's a blocker for enzymejs/enzyme#2554. Operational wise, how should we do it? A branch on my fork? Another PR?
There was a problem hiding this comment.
@pablopalacios please post a link to a branch on your fork - NOT a separate PR - and i can pull its changes into this PR. Thanks!
There was a problem hiding this comment.
There was a problem hiding this comment.
@unverbraucht @dcpesses after adding some tests, I tried both versions. elementType is the right one (and the one that makes sense since we extract the legacy context from it as well).
Co-authored-by: Kevin Read <me@kevin-read.com> Co-authored-by: Pablo Palacios <pablo.palacios@holidaycheck.com>
|
@pablopalacios i've updated the PR, but there's still no tests or anything. |
|
@ljharb I've updated my branch with the tests. I also renamed the tests that are using the legacy |
Hi all,
the patch posted on enzymejs/enzyme#2189 adds support for class based components that pass the context via .contextType. This is the part of the patch that applies to react-shallow-renderer.