bUnit - knowing all OnInitializedAsync() have completed and IRenderedComponent.Render()

78 views Asked by At

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. This is for a bUnit test.

  1. 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:
    1. Have a MyPage.IsLoaded property and then call rc.WaitForState(() => rC.Instance.IsLoaded)
    2. Have the call rc.WaitForState(() => rc.FindAll(" ... ").Count > 0) where it is finding the html node at the end of the rendering in the last inner component.

I'm not wild on solution 1.2 as that assumes I know which inner component will render last. Solution 1.a works because IsLoaded is set to true in OnAfterRender() and therefore I know everything is good.

  1. Why would I call IRenderedComponent.Render() to re-render the page? Is it:
    1. To solve the above problem #1? So it then renders the page twice, but I now know it is fully rendered?
    2. Is it to be the equivalent of calling StateHasChanged() in the page code? So I can set some parameters and then I need it to re-render for those new values?
0

There are 0 answers