-
In a number of my tests I occasionally get this exception:
The problem is that it does not happen every time. More than not, my tests are passing. Only occasionally, I get this error. Always in the tests for the same component, but that might not be related, as the component in question has the most tests. In this component tests, I register js mocks in the constructor like this: public MultiRangeSlider_Moving_Mouse_Tests()
{
JSInterop.Setup<OverlayPosition>(JSInteropConstants.OverlayComponentHelper.AddOverlayToContainer, _ => true)
.SetResult(new OverlayPosition());
JSInterop.Setup<OverlayPosition>(JSInteropConstants.OverlayComponentHelper.UpdateOverlayPosition, _ => true)
.SetResult(new OverlayPosition());
JSInterop.Setup<string>(JSInteropConstants.AddDomEventListener, _ => true)
.SetResult("");
JSInterop.Setup<HtmlElement>(JSInteropConstants.GetDomInfo, _ => true)
.SetResult(_sliderDimensions);
#if !NET6_0_OR_GREATER
JSInterop.SetupVoid(JSInteropConstants.Focus, _ => true);
#endif
} I have a feeling I am doing something wrong, but I cannot spot the mistake. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Interesting. If I read that stack trace right, the exception is coming from Blazors renderer. My guess is that it happens because your component under test is doing async work and is still adding components to the render tree when the test exits the test method. This might help hint at a solution: https://bunit.dev/docs/interaction/awaiting-async-state.html |
Beta Was this translation helpful? Give feedback.
Interesting. If I read that stack trace right, the exception is coming from Blazors renderer. My guess is that it happens because your component under test is doing async work and is still adding components to the render tree when the test exits the test method.
This might help hint at a solution: https://bunit.dev/docs/interaction/awaiting-async-state.html