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

Allow to render child custom component in shallow renderer #5513

Closed
wants to merge 1 commit into from

Conversation

lasekio
Copy link
Contributor

@lasekio lasekio commented Nov 20, 2015

Motivation: https://medium.com/@bruderstein/the-missing-piece-to-the-react-testing-puzzle-c51cd30df7a0#.o7qri0ufc

Currently there is no way to easy refactor spaghetti components by smash them into smaller components while using shallow renderer to test. It fixes that.

I know, that inject custom instantiateReactComponent function is tricky, but I did not find better solution for this. I'm open for suggestions to do it better, maybe some core devs have some ideas?

Im also not convinced about add components to the "whitelist" - renderComponentsAsChild array. This name does not explain purpose enough for me. Again, I'm open to any suggestions.

The plus is, that there is no any regression in this but I'm little scary, that tests dont cover all corner cases so probably it should go as 0.15 release's feature, because users could report some bugs with them tests.

@facebook-github-bot
Copy link

@Laskos updated the pull request.

@gaearon
Copy link
Collaborator

gaearon commented Mar 27, 2016

Thank you for taking time to contribute. I don’t think we want to take this particular PR as a part of the shallow renderer but you are welcome to raise an issue to explain the motivation behind this in more detail.

Shallow renderer tests components one level deep by design. If you want to split components, you are also expected to split the corresponding tests. You can use rendering to something like jsdom if you would like to run tests on the whole component tree. Something like https://github.com/airbnb/enzyme/ can help smooth over the API differences between regular and shallow rendering.

Partially deep rendering may be something we want to support but it is better to discuss this as an issue first, and reach a consensus on the API as well as explain the use cases there. Please feel free to raise such an issue if you think this is an important missing piece in React. Thanks!

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.

None yet

3 participants