Are you certain that the task returned from your AppSettingsDataService.Get()
method ever completes?
I would make sure that the task returned from AppSettingsDataService.Get()
is already completed, otherwise you need to a way to complete the task after the component is rendered. There are many ways to do this, it all depends on how your mock is implemented.
As for your WaitFor
, you can just use the WaitForAssertion
method in this case, i.e.: cut.WaitForAssertion(() => cut.MarkupMatches("<p>Hello World</p>"));
A little background:
The WaitFor*
methods are used when the component under test is being rendered asynchronously, since the test, running in a different thread, doesn't know when that will happen.
In general, you should never need to set a custom timeout, the default is 1 second, but the WaitFor*
methods will retry the assertion/predicate every time a renderer happens. Its only when the thing that triggers the rendering will take more than one second, e.g. if you are using bUnit to perform end-2-end testing and e.g. pulling data from a real web service.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…