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

Add support for passing context to React class based components via contextType #2507

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

unverbraucht
Copy link

Based on the patches posted in #2189 (comment) by @forivall (thanks!).

Adds changes to ReactSixteenAdapter and simple test case.

Add support for passing context to React class based components that request context via setting .contextType, according to patches posted in enzymejs#2189 (comment). Adds changes to ReactSixteenAdapter and simple test case.

Co-authored-by: Kevin Read <[email protected]>
Co-authored-by: Pablo Palacios <[email protected]>
@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #2507 (5e1ca3c) into master (3d286a4) will decrease coverage by 24.34%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master    #2507       +/-   ##
===========================================
- Coverage   96.31%   71.97%   -24.35%     
===========================================
  Files          49       49               
  Lines        4207     4210        +3     
  Branches     1130     1132        +2     
===========================================
- Hits         4052     3030     -1022     
- Misses        155     1180     +1025     
Impacted Files Coverage Δ
...enzyme-adapter-react-16/src/ReactSixteenAdapter.js 95.49% <100.00%> (+0.02%) ⬆️
...r-react-13/src/ReactThirteenMapNativeEventNames.js 0.00% <0.00%> (-100.00%) ⬇️
...adapter-react-13/src/ReactThirteenElementToTree.js 4.16% <0.00%> (-95.84%) ⬇️
...-adapter-react-15.4/src/ReactFifteenFourAdapter.js 8.67% <0.00%> (-87.87%) ⬇️
...nzyme-adapter-react-14/src/ReactFourteenAdapter.js 9.21% <0.00%> (-87.50%) ⬇️
...enzyme-adapter-react-15/src/ReactFifteenAdapter.js 9.93% <0.00%> (-86.10%) ⬇️
...e-adapter-react-16.1/src/ReactSixteenOneAdapter.js 9.92% <0.00%> (-85.12%) ⬇️
...e-adapter-react-16.2/src/ReactSixteenTwoAdapter.js 10.18% <0.00%> (-84.91%) ⬇️
...nzyme-adapter-react-13/src/ReactThirteenAdapter.js 13.66% <0.00%> (-81.30%) ⬇️
...ackages/enzyme-adapter-react-helper/src/ifReact.js 33.33% <0.00%> (-66.67%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d286a4...5e1ca3c. Read the comment docs.

@unverbraucht
Copy link
Author

Hmm, the new unit tests are failing, but they're working locally here. I'll try to reproduce this with the respective build configurations

@unverbraucht
Copy link
Author

My bad. The tests are expected to fail because they use the unpatched react-shallow-renderer :)

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a test that changes the provided value, and ensures that the new value also shows up?

it('works on a Provider', () => {
const wrapper = shallow(<OuterComponent />);
const provides = wrapper.find(Provider).dive();
const provider = provides.find(InnerComponent).shallow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const provider = provides.find(InnerComponent).shallow();
const provider = provides.find(InnerComponent).dive();

any reason this wouldn't work?

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx Outdated Show resolved Hide resolved
@ljharb

This comment was marked as outdated.

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

Successfully merging this pull request may close these issues.

2 participants