-
-
Notifications
You must be signed in to change notification settings - Fork 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
API differences between render and mount/shallow #465
Comments
render
render
and mount
/shallow
render
and mount
/shallow
Wouldn't this break most existing tests that user |
|
Thank you both for taking the time to anwser this. @aweary Yes, this would be breaking the existing API, which I agree is an inconvenience @ljharb Fair enough. The difference in API is assumed and it's OK. However the docs say:
Which does not seem perfectly accurate (I'm a PITA I know 😄) Playing with the different methods that enzyme provides, I have seen this: ShallowReal unit test (isolation, no children render) Simple shallowCalls:
Shallow + setPropsCalls:
Shallow + unmountCalls:
MountThe only way to test componentDidMount and componentDidUpdate. require('fbjs/lib/ExecutionEnvironment').canUseDOM = true; Simple mountCalls:
Mount + setPropsCalls:
Mount + unmountCalls:
Renderonly calls render but renders all children. So my rule of thumbs is:
There seems to be a very tiny use case for render. I wonder if it would be possible to emulate lifecycle methods with the I'm also curious to know why shallow does not call componentDidUpdate. |
Render is useful when you just want to assert on the DOM your component(s) render. This is a common case for static sites that use I'm going to close as I don't think we'll be taking any action on this, but we really appreciate the issue/discussion @geowarin! |
Is it possible to execute componentWillMount with shallow? Perhaps calling it manually in some way? I.e.
Enzyme does not support mount in React Native, so I'm looking for a way to test some logic within componentWillMount. Thanks! |
Nevermind! It appears this was resolved in #318 |
@geowarin hi! Thanks for the comment #465 (comment), it is great and helped me understand better the difference between shallow and render. Also, sometimes Full DOM Rendering is called Full Rendering. Do you think it could be beneficial to indicate, in the docs, the various lifecycle methods for each rendering methods, as well as their intrinsic features (like no-children rendering etc.)? |
@geowarin Thank you for the clarification about the diff between shallow, mount and render! |
@joncursi correct me if I'm wrong, but doesn't
already call componentWillMount once? |
For all readers now. LifeCycleExperimental which was previously an option that you had to manually set to true on shallow is now enabled by default because it is now stable. This is much nicer than having to resort to mount when wanting to test lifecycles. This means all lifecycle methods work with |
@Raju10100 please file a new issue and do not spam multiple closed issues with your comment. I’m deleting this one since it’s a duplicate. |
This is more of a question than an issue. I'm trying to see where you guys want to go with the
render()
function.I like it but the API feels awkward sometimes.
For example, it is not possible to do this:
Error:
In cherrio's documenation, the pattern to map elements is:
So the workaround seems to be:
which is kind of ugly and contrasts with the nice APIs of
render()
andmount()
.A solution would be to return a wrapper in the render function instead of
cheerio.load(html).root()
.Something along the lines of:
This looks like some work but it would have the advantage of proposing a unified API for
mount()
,shallow()
andrender()
.So the question is: what is your roadmap for the
render
function ?The text was updated successfully, but these errors were encountered: