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 option for childContextTypes of ReactWrapper #171

Merged
merged 2 commits into from
Feb 10, 2016

Conversation

jakubzitny
Copy link
Contributor

Fixes #144.

// In that case, we define both a `getChildContext()` function and a `childContextTypes` prop.
let childContextTypes = node.type.contextTypes;
if (options.childContextTypes) {
childContextTypes = options.childContextTypes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we merge node.type.contextTypes and options.childContextTypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's probably better. I'll update this, however, I think there should be better automatic fix to this issue.

@lelandrichardson
Copy link
Collaborator

@jakubzitny I suppose you mean by traversing the tree and finding the required context types of the descendants?

I'm really not sure if this is possible. At the time this code executes, the node is only the output of React.createElement() on the root node you are mounting. Traversing it's rendered subtree would require actually rendering, which we can't do until this component is created.

It's possible I'm not fully grokking the way context is working, but i'm unsure how react itself solves this if this is how context works.

@jakubzitny
Copy link
Contributor Author

@lelandrichardson Yeah I meant something like that. I know it's not really possible without rendering. :(

I was thinking about just looking at the contextTypes of all children somehow. Isn't it really possible to get the children of a component without rendering somehow? By looking at the render function, or just rendering it shallowly, then getting the children from props().children and then rendering shallowly their children, or something like that?

The thing is that in React if you do this, you always specify both childContextTypes and also getChildContext. So it is not handled automatically. But for the test cases with enzyme it'd be great if it was automatic, so you wouldn't need to specify that many things and making the tests longer..


Btw I pushed a fixup for merging both childContextTypes. I will rebase it if you want to accept this PR.

@lelandrichardson lelandrichardson added the semver: minor New stuff. label Feb 10, 2016
@lelandrichardson
Copy link
Collaborator

Going to go ahead and merge this in. I think this is the best way to do this at this point. Open to PRs for alternatives though.

lelandrichardson added a commit that referenced this pull request Feb 10, 2016
add option for childContextTypes of `ReactWrapper`
@lelandrichardson lelandrichardson merged commit 0b7c31d into enzymejs:master Feb 10, 2016
@blainekasten
Copy link
Contributor

Is there any specific reason this wasn't built into the shallow wrapper API?

@jakubzitny
Copy link
Contributor Author

jakubzitny commented Apr 17, 2016

@blainekasten there is no need for it in ShallowWrapper.. (the problem was with context of deeper child nodes, there are none in ShallowWrapper)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor New stuff.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants