enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

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

Open unverbraucht opened 3 years ago

unverbraucht commented 3 years ago

Based on the patches posted in https://github.com/enzymejs/enzyme/issues/2189#issuecomment-796416083 by @forivall (thanks!).

Adds changes to ReactSixteenAdapter and simple test case.

codecov[bot] commented 3 years ago

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%) :arrow_up:
...r-react-13/src/ReactThirteenMapNativeEventNames.js 0.00% <0.00%> (-100.00%) :arrow_down:
...adapter-react-13/src/ReactThirteenElementToTree.js 4.16% <0.00%> (-95.84%) :arrow_down:
...-adapter-react-15.4/src/ReactFifteenFourAdapter.js 8.67% <0.00%> (-87.87%) :arrow_down:
...nzyme-adapter-react-14/src/ReactFourteenAdapter.js 9.21% <0.00%> (-87.50%) :arrow_down:
...enzyme-adapter-react-15/src/ReactFifteenAdapter.js 9.93% <0.00%> (-86.10%) :arrow_down:
...e-adapter-react-16.1/src/ReactSixteenOneAdapter.js 9.92% <0.00%> (-85.12%) :arrow_down:
...e-adapter-react-16.2/src/ReactSixteenTwoAdapter.js 10.18% <0.00%> (-84.91%) :arrow_down:
...nzyme-adapter-react-13/src/ReactThirteenAdapter.js 13.66% <0.00%> (-81.30%) :arrow_down:
...ackages/enzyme-adapter-react-helper/src/ifReact.js 33.33% <0.00%> (-66.67%) :arrow_down:
... 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 commented 3 years ago

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 commented 3 years ago

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

ljharb commented 3 years ago

We'll also need the same changes in the 16.3 adapter, I suspect.