enzymejs / enzyme

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

`.dive()` doesn't work well with component using `useContext()` #2165

Open chenesan opened 5 years ago

chenesan commented 5 years ago

This issue is for closing #2011 and tracking the skipped shallow test.

Current behavior

See skipped shallow test in https://github.com/airbnb/enzyme/blob/master/packages/enzyme-test-suite/test/shared/hooks/useContext.jsx#L50-L54 . After .dive() call in the internal component the context value is still initialTitle in .shallow(), not the value from outer <Provider />.

Expected behavior

In that test the text value should be as same as value from outer <Provider />.

Your environment

API

Version

library version
enzyme master branch
react 16.8.6
react-dom 16.8.6
react-test-renderer 16.8.6
adapter (below) master branch

Adapter

ljharb commented 5 years ago

This seems related to #2114, I suspect.

atsikov commented 5 years ago

Just for a note: most likely connect from react-redux doesn't work properly with shallow.dive because of this issue. Some minimal repro: https://codesandbox.io/s/old-currying-4lme5 (which seems to be similar to the skipped test above)