Exception caught with bUnit

I have a component that has a boolean Parameter which is binded to a Radzen Switch

<RadzenSwitch @bind-value = "@IsSelected"
id = "@_IdAppSwitch"
class = "mr-2"
Change = "@OnSwitched">

In my test case, here's how I invoked the bUnit rendering:

ComponentParameter[] paramList = new ComponentParameter[]
{
, Parameter("IsSelected", true)
};

IRenderedComponent card = cntxt.RenderComponent(paramList);

Interestingly, when I set IsSelected to false (or not setting it at all), it works fine...but if I set IsSelected to true...I get this error:

Bunit.JSRuntimeUnhandledInvocationException : The invocation of 'Radzen.preventArrows' with the argument [Microsoft.AspNetCore.Components.ElementReference] was not expected.

Anyone has any idea why?

It turns out that the Radzen component needs to run some JavaScript, but it's not available when testing with bUnit.
I circumvented the problem by cntxt.JSInterop.Mode = JSRuntimeMode.Loose;

Where cntxt is TestContext() from bUnit.

3 Likes