Knowing all OnInitializedAsync() have completed and IRenderedComponent.Render() #1251
Replies: 3 comments 4 replies
-
Hey,
In
You would call this method if you change/setup something in your test that should be reflected in your Blazor code. For example, you change the authorization in your test and want to reflect those changes to your production code. Or you change a two-way bound variable or cascading parameter that you defined in your testcode. |
Beta Was this translation helpful? Give feedback.
-
Hi; Thanks for answering. And on the "everything has rendered" issue - you're having to make up for a shortcoming in Blazor so that's on them, not you.
|
Beta Was this translation helpful? Give feedback.
-
You have to frame the problem slightly different, I think. The reason why you want to wait for all OnInitAsync to complete is because you are aware of how your components work internally. However, your tests should not rely on implementation details, if at all possible. If they don't, you are able to refactor your components without breaking your tests. Instead, when you create tests, focus on the externally observable behavior of your components, i.e. look at them from the end users point of view. So, if you are waiting for your components to render, then that probably means there are certain things available in the DOM ( So instead of waiting for internal state, e.g. |
Beta Was this translation helpful? Give feedback.
-
Hi all;
I think the first part of this question may be answered by the second part, but I'm asking each in case I don't fully understand all this.
How do I await until OnInitAsync() has completed for my page, including for every child component in it? In my particular use case I have pages where the page itself has no OnInitializedAsync() call but has several components that each have a OnInitializedAsync() that is hitting the database. If I go to test immediately, I get the "Is Loading" text on the page. I want to assert the page after it is fully populated. The solutions I see are:
Have a MyPage.IsLoaded property and then call
rc.WaitForState(() => rC.Instance.IsLoaded)
.Have the call
rc.WaitForState(() => rc.FindAll(" ... ").Count > 0)
, once for each inner component, finding the html node at the end of the rendering in each of the inner components.I'm not wild on solution 1.i as that requires the inner components talk to the parent telling it when they're all rendered. And 1.ii is messy, but it should work.
Why would I call IRenderedComponent.Render() to re-render the page? Is it:
thanks - dave
Beta Was this translation helpful? Give feedback.
All reactions