Testing component with OnInitializedAsync #615
Replies: 2 comments
-
Hi Sean, Its hard to know without seeing the complete test and component under test. A few notes though: First of, you generally dont need to specify a long timeout. It is only needed if you have async code that you know for a fact might run long, e.g. a real database/web service call that takes more than one second. If you are controlling the async operations during testing, e.g. by mocking the data such that it returns immediately, then it should take less then a millisecond on a regular computer, and you do not have to extend the default timeout. The different Second, it is pretty uncommon to need to use the async version of the event trigger methods (e.g. Where you problably need to look is in the event handler on the |
Beta Was this translation helpful? Give feedback.
-
That's exactly what I'm doing. I'm mocking the dependency (one or more) that would otherwise make HTTP calls, and return the data. And yet, still, I'm running into this issue that I have to wait for the state using I'll play more with bUnit and hopefully will find my problem. Thank you, @egil. |
Beta Was this translation helpful? Give feedback.
-
I'm following the documentation guidance on how to test with
OnInitializedAsync
loading data asynchronously.The component is loading data for a
select
element inOnInitializedAsync
, rendering all the controls once the data is loaded.And on the razor page, inputs are only rendered when
dataLoaded
istrue
:To validate the happy path, I'm populating all the inputs and ensuring to wait for the state change in the following way:
and right after that, updating all the form fields and submitting the form
But
WaitForState()
fails withI've tried
But then I get random input that is not found, like "No elements were found that matches the selector '#firstName'"
I feel like I'm doing something wrong if
WaitForState()
doesn't work. When the number of the input elements is reduced, it works.bUnit 1.4.15
.NET 6
Beta Was this translation helpful? Give feedback.
All reactions