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

Filter legacy context on childContextTypes when necessary #1968

Merged
merged 2 commits into from Jan 14, 2019

Conversation

@minznerjosh
Copy link
Contributor

minznerjosh commented Jan 7, 2019

Fixes #1590

In react-test-renderer@16.0 - 16.2 there's an issue where context is not filtered to a component's childContextTypes. This issue is not present in react-test-renderer@<16 or react-test-renderer@>=16.3. This PR implements the same fix as react-test-renderer@16.3 for enzyme adapters using react-test-renderer that have the issue.

@minznerjosh minznerjosh force-pushed the trialspark:josh__filter-shallow-context-to-context-types branch from 921a1a2 to 4931b45 Jan 7, 2019

@ljharb
Copy link
Member

ljharb left a comment

Thanks!


const context = { name: 'foo', hello: 'world' };
const wrapper = shallow(<Foo />, { context });
expect(JSON.parse(wrapper.find(Bar).dive().text())).to.eql({ name: 'foo' });

This comment has been minimized.

@ljharb

ljharb Jan 8, 2019

Member

instead of using json and text here, could the test assert that wrapper.find(Bar).context() was the expected object?

return {};
}
const context = {};
Object.keys(contextTypes).forEach((key) => {

This comment has been minimized.

@ljharb

ljharb Jan 8, 2019

Member

Let's do this:

return fromEntries(Object.keys(contextTypes).map(key => [key, unmaskedContext[key]]));

(with import fromEntries from 'object.fromentries')

@minznerjosh minznerjosh force-pushed the trialspark:josh__filter-shallow-context-to-context-types branch from 4931b45 to eb0819e Jan 8, 2019

@minznerjosh

This comment has been minimized.

Copy link
Contributor

minznerjosh commented Jan 8, 2019

@ljharb feedback addressed and rebased!

@minznerjosh minznerjosh force-pushed the trialspark:josh__filter-shallow-context-to-context-types branch from eb0819e to 865e740 Jan 8, 2019

@ljharb ljharb force-pushed the trialspark:josh__filter-shallow-context-to-context-types branch from 865e740 to 884f306 Jan 14, 2019

@ljharb

This comment has been minimized.

Copy link
Member

ljharb commented Jan 14, 2019

I've rebased this and added some adapter-utils unit tests (and added the fix to the 16 adapter, which has to work with 16.0 - 16.7)

@ljharb ljharb force-pushed the trialspark:josh__filter-shallow-context-to-context-types branch from 884f306 to c7282eb Jan 14, 2019

@ljharb

ljharb approved these changes Jan 14, 2019

@minznerjosh

This comment has been minimized.

Copy link
Contributor

minznerjosh commented Jan 14, 2019

Whoops! Sorry for leaving out tests for the adapter utils. I would’ve been happy to add them, but I understand it was probably easier for you to just do it yourself. 😊

I’ll double-check my other PRs to make sure I haven’t left any other modules untested.

@ljharb ljharb merged commit c7282eb into airbnb:master Jan 14, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@minznerjosh minznerjosh deleted the trialspark:josh__filter-shallow-context-to-context-types branch Jan 14, 2019

@ljharb

This comment has been minimized.

Copy link
Member

ljharb commented Jan 14, 2019

@minznerjosh nbd, i appreciate it :-)

@ljharb ljharb added this to In progress in context interaction via automation Jan 14, 2019

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