-
-
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
Support all Component Lifecycle methods in ShallowRenderer #318
Support all Component Lifecycle methods in ShallowRenderer #318
Conversation
@koba04 This is really cool work. I had briefly considered something similar to this a while ago but never pursued it. I like this idea in general, but let me voice a couple of things concerning me:
This PR would be a big breaking change and would push us to 3.0. As a result, I might choose to sit on it for some amount of time, as we had a couple of other things planned for 3.0. This is great work though and would be a welcome addition. |
Thank you for your great feedbacks 😄
yeah, refs doesn't work in this implementation because Shallow Rendering doesn't support it yet.
right. I'll add tests for context and try to work it well if it doesn't work.
I'll add tests for when setState is called in lifecycle methods. I guess it works well except batchingUpdate feathers.
I guess so. I'll confirm the original behaviors of React. Currently, this PR is including very minimum implementations. |
This would be fantastic. My shallow rendering tests are chock full of x.instance().componentDidMount(). Would ref support be a blocker for this PR getting released considering the underlying shallow renderer from React just doesn't support them? |
I think ref support is not a blocker for this PR. Because it is a limitation of Shallow rendering. Current I might be able to add the refs support in this PR. But it would be better to implement it in React Shallow rendering instead of including it in enzyme. This PR is in an early stage. I have to solve some issues and write some test cases. |
@koba04 any progress on this since? I'm super interested in seeing this merged |
@aweary
I think this can be merged if #342 is merged and I've ensured that the lifecycle methods are called properly. |
Is #342 required for Most lifecycle methods are invoked in
|
@aweary Thank you for your feedbacks! I think the following cases should be batching updates.
For supporting the above, I'm going to use #342 . |
Got it, so that PR should make As far as execution order goes this seems generally in line with |
Yeah, I'm considering to support Refs. I think I have two options for it.
|
This is great to see someone ( @koba04 ) taking this on! We have been also performing similar hacks (i.e. |
The reason Historically Adding in full lifecycle support for components that don't use If we could somehow make this API an opt-in feature, then I don't think support for refs would be needed at all. One thing we could do starting off is provide it as an "experimental" flag:
or something like that. @koba04 what are your thoughts? |
SECRET_LIFECYCLE_DO_NOT_USE_OR_YOU_WILL_BE_FIRED |
more like EXPERIMENTAL_LIFECYCLE_DO_NOT_GET_MAD_AT_US_IF_BEHAVIOR_CHANGES :) |
I think it is a good first step for supporting lifecycle methods! I agree with supporting https://facebook.github.io/react/docs/test-utils.html#shallow-rendering I think supporting I'd like to take this too, but I'd like to take as an another issue. |
Right, Supporting I think it's no longer shallow... We need to discuss how |
224d320
to
9c23b67
Compare
interesting.
|
Looks like there might be another renderer for Enzyme to wrap 😅 As described, I don't think the new test renderer would make shallow rendering any less valuable. If there was a switch or option to turn off deep rendering, though, that would be interesting. |
If anything it seems to be closer to @spicyj how do you think this new renderer might affect enzyme? |
Yes, it's like |
@spicyj very interesting, thanks for chiming in. JSON should be just about as easy as it gets for us in terms of consuming/wrapping the API. Sounds like a great middle-ground between |
8422734
to
3a13125
Compare
I've implemented To be clear, the following tables are differences of behavior by the flag. mounting phase
updating phasesetState
setProps and setContext
unmounting phase
|
@koba04 could we have a test asserting the order in which lifecycle hooks are called, especially those related to updates? |
@thatguynamedandy It's fixed in 2.4.1. Thank you for reporting it! |
Thanks for all the great work @koba04 🎉 |
Did we ever remove the |
I've created a PR for React supports all lifecycle methods in ShallowRender. If the PR is merged, we can remove this implementation and enable this without |
@koba04 we'd still need to support React 0.13, 0.14, and v15, so we'd have to think carefully about how we maintain compat across all React versions. |
@ljharb Sure. That PR has a breaking change, so I think these are possible to exist together by using the |
Does facebook/react#9426 allow it to be enabled by default? |
@nevir No, ShallowRenderer v16 will behave the same way. I think it would be nice if ShallowRenderer supported this in a future major release. |
thank you @koba04 for this PR! just read through the whole thread simply because I was curious of the culmination of this feature |
@nxmohamad |
hi @koba04 Thank you very much for the work done, it has been very helpful. With this last comment you put, I finally make sense of a problem I'm going through #1279. My Info:
I am testing and apparently this is a problem related to redux interactions. When I change my redux In case this is not yet available for |
Hi, @jose920405
According to this comment, are you using Currently, enzyme has a bug that doesn't call componentDidUpdate for setState if you don't enable lifecycleExperimental. This is a PR to fix this #1261. |
Yeah, i'm using
My code: My LoginScreen Component
My Test File:
It works as expected, runs the change on my reducer, and causes the render to run again. componentDidUpdate DOES NOT FIRE. and as I mentioned earlier, running |
@jose920405 |
When you say.
This is something that is not clear to me, since it works very well for me. If we go to my example inside
results in the My problem is directly with redux actions and not with |
@jose920405 Thanks, That's a weird behavior. Could you create a repository or gist to be able to confirm this? |
hi @koba04 apologies for the delay, I was quite busy in other things these days 🙂 This is the repo with the example. https://github.com/jose920405/example-react-native-redux-with-enzyme unfortunately I have not been able to replicate what I say to you if the But I'm still testing it on my original project and there if I still use the This is my proving: For now it is happening to me what it says that the I wanted to thank you for your work in this functionality. I also wanted to ask you about your progress and if you have a close estimate of when you can be ready. I look forward to this work to continue my test. |
@jose920405 Thanks for creating the repo! |
This is a feature request which is supporting all React Component Lifecycle methods.
This is including some breaking changes.
This implementation is working on progress, and no (tests is passed)
Does this make sense?
If you are interested in this PR, please give me your feedbacks.
I'd like to work on it 😄
Thanks.