-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Shallow Renderer should expose rendered component instance #4056
Comments
A hacky workaround is to access the internals of the ReactShallowRenderer but this seems like something which should be part of the public API. |
Yea, I agree that it is probably useful as a convenience similar to refs. Since a ref could expose a public API which can be tested. It is probably bad practice to call handlers or inspect state directly though. It is better to test the public API by invoking the callbacks of the render output. |
@sebmarkbage |
At the moment there's no way to test things like componentDidMount or componentDidUpdate via shallow rendering, exposing the instance would provide a way to do this. |
I've put together a side-by-side comparison of lifecycle support between "normal" rendering and "shallow" rendering. Exposing http://jsfiddle.net/xvs6xdfk/3/ Output using normal rendering
Output using shallow rendering
We're heavy shallow rendering users on the current project at work - we're using https://github.com/glenjamin/skin-deep to provide some helper functions - including adding We should be able to contribute a PR for this if we get some steer on the best way to proceed. |
Is it worth creating a new issue specifically for 'ensuring shallow rendered components can be progressed through the full lifecycle' eg. not leaving out |
@jsdf Yea, that seems reasonable so that they can be addressed separately. Both seems reasonably simple though so a pull request would be welcome. |
Just as
ReactMount.render
returns the rendered component instance, it seems to me thatReactShallowRenderer.prototype.render
should return the rendered component or expose it in some other way (maybe agetRenderedComponent
method) so that when testing stateful components via shallow rendering, assertions can be made against the state of the component instance.The text was updated successfully, but these errors were encountered: