-
Notifications
You must be signed in to change notification settings - Fork 92
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
Discuss desired behavior of rerender #365
Comments
Do you want to create a PR for this change @shaman-apprentice ? |
BREAKING CHANGE: Use erender instead of change. Use erender instead of changechangeInput For more info see #365
BREAKING CHANGE: Use erender instead of change. Use erender instead of changechangeInput For more info see #365
BREAKING CHANGE: Use `rerender` instead of `change`. Use `rerender` instead of `changechangeInput`. For more info see #365
* feat: upgrade to @testing-library/dom 9 (#376) BREAKING CHANGE: For more info see https://github.com/testing-library/dom-testing-library/releases/tag/v9.0.0 * feat: remove change and changeInput in favor of rerender (#378) BREAKING CHANGE: Use `rerender` instead of `change`. Use `rerender` instead of `changechangeInput`. For more info see #365
I know that I'm pretty late to this party but this is change seems like a stepback. The way await rerender({ componentInputs: { firstName: 'John', lastName: 'Smith' } });
// result: John Smith
await rerender({ componentInputs: { lastName: 'Smith' } });
// result: Smith
await rerender({ componentInputs: { firstName: 'Jacob' }, partialUpdate: true });
// result: Jacob Smith |
Thanks for joining the party and your input :) Following just my quick evening thoughts:
I still think this was a good idea. My two main selling points are still:
Good catch! Would you mind to create a PR to update it? If you don't have time, I can do that too.
I haven't checked, but isn't it possible to call
How much to test in a single test is a trade off / heavily opinionated, in my opinion.^^ Without any context I would say that tends to be a good thing.
That way we can now test the behavior of Would it maybe be possible to split your inputs into variables you want to update and those you want to change? Or use some kind of test data builder? That would be DRY and also be more explicit about what will change in your test.
At first glance, I am open to the idea. If agreed within on own issue / feature request I would be willing to create a pull request for it. |
Thank you for taking time to respond to this.
I haven't thought about this much, also I'm not familiar with testing library for react, but yeah.. it makes sense what you're saying. Although, after looking into the React's API and playing around with it I have to say it looks weird 😄 mainly because
Yeah, I can do that, just wanted to raise these thoughts first.
Unfortunately, no,
I see what you mean. To be honest, after refactoring my test cases that were affected by this chagne I do not have a strong opinion about this anymore.
Totally agree but previously you could also test
This is exactly what I started doing with this change. But still, with bigger components that have many inputs it makes the test code very verbose and kind of asks for additional comments as the code is no longer self-explanatory. // you no longer can tell which inputs have actually changed and which you're just passing through
// without tracking every variable to see when/if they were changed before calling `rerender`
await rerender({ componentInputs: { formControl, fooObject, barObject, fooBarObject } });
// previously you could have a good idea of the test case just from this line of code
// because you know that you're changing this one input only:
change({ formControl });
If you still feel that way, I can open a new issue (only regarding the properties/input change improvements, I'm not so much interested into the rerender from scratch thing anymore). |
Hi, currently I went also through this "nightmare" of refactoring
|
Hi, it took me a while to get to this issue, but I see that @shaman-apprentice already has provided more insights on why we made this change. I'm sorry to hear that this change broke many tests @dzonatan and @Roman-Simik , I think we deprecated it in the last version, but maybe we had to keep it one more version. This is something to keep in mind for the future. This library aims to be compatible with the other Testing Library projects, and with how Angular interacts with components. But, on the other we also want to bring the joy into writing tests, and making it easier to test Angular applications. I like the idea of having an overload of So, the default behavior of await rerender({ componentInputs: { firstName: 'Jacob' }, partialUpdate/partial: true });
await rerender({ componentInputs: { firstName: 'Jacob' }}, true);
await rerender({ componentInputs: { firstName: 'Jacob' }}, { partialUpdate/partial: true }}); What do you think about this? To get back on why we can't run |
I have a question about the new rerender method. I ran into an issue in which some child components where not destroyed upon an event. I wanted to simulate the same behavior in testing library. However when I used rerender the components were destroyed, unlike the behavior in the browser. Is it possible that it still rebuilds the renderresult from scratch, instead of just calling the ngChanges? Or maybe the state of injected services are reset? I am sure that something more happens. I am using version 15.1.0 of testing library/angular. |
@Henksen can you provide a minimal example for your unwanted behavior? I think I would have time next Weekend to dig into a minimal example |
Feel free to create a new issue for this with a reproduction. |
Current behavior of
rerender
It destroys old component and creates a new one from scratch with given properties.
My thoughts on it
rerender
does not suggest to me, that component is created from scratch nor old one is destroyed.rerender
does keep existing instance, meaningconstructor
of class andcomponentDidMount
will not be called.render
andcomponentDidUpdate
will get called. Therefore I thinkrerender
should not create the component from scratch but callngOnChanges
with simpleChange parameter containing previous values. Not passed in properties should be removed.rerender
seems to update props instead of replacing them #252 should work withrerender
When the component in
rerender
is not created from scratch, I think change is not useful anymore. All properties are controlled from outside. So we can pass in all properties we want to keep inrerender
unmodified again. I guess that's why React's API doesn't have an equivalent ofchange
.The text was updated successfully, but these errors were encountered: