Hi ! My team and I are pretty new with Bunit and Blazor and we were wondering if there is a clean way to assert that a component has not been rendered in an Integration test context where the component under test is always the
Index component and all services are injected with their real implementation excepting the
HttpClient that is mocked with the suggested NuGet.
Currently, we are relying on time to assert that its has not been rendered like the following :
Action getComponentX = () => cut.FindComponent<X>; cut.WaitForAssertion(() =>getComponentX.Should().Throw<WaitForFailedException>(), TimeSpan.FromSeconds(3));
A concrete exemple of the production use case would be when there is an
Also, is there any hook letting us know when the Index and all its child component has finished rendering and all the async initialization have been completed ?
in general, after a call to RenderComponent (or Render), the full render tree has been created. Then you can use cut.WaitForState. Its predicate will be called after each render, so if you have one or more async renders happening after the initial render, that predicate will be called after each.
<form>and matches the
cutmarkup which is also a
<form>? As I say, I could be wrong.
Render(@<MyComp @bind-Value="variable" />)
MyCompwith an input field that is linked/bound to a Value parameter, and when it is changed, the ValueChanged EventCallback is triggered, then the following should work:
var value = "initial"; var cut = RenderComponent<MyComp>(ps => ps.Add(p => p.Value, value).Add(p => p.ValueChanged, x => value = x))); cut.Find("input").Change("new value"); Assert.Equal("new value", value);
var value = "initial" var cut = Render(@<MyComp @bind-Value="value" />); cut.Find("input").Change("new value"); Assert.Equal("new value", value);
cut.Find("input").Change("new value");triggers the MyComp component to push changes to its
setparamdoesn't seem to cut it
<MudGrid> <MudItem xs="12" sm="4"> <MudAutocomplete T="string" Label="US States" @bind-Value="ActiveStringHolder.StringValue" SearchFunc="@Search1" ResetValueOnEmptyText="@resetValueOnEmptyText" CoerceText="@coerceText" CoerceValue="@coerceValue"/> </MudItem> <MudItem xs="12" sm="4"> <MudButton OnClick="(()=>ToggleValue())" Variant="Variant.Outlined">Toggle Value</MudButton> </MudItem> <MudItem xs="12" md="12" class="flex-column"> <MudSwitch @bind-Checked="resetValueOnEmptyText" Color="Color.Primary">Reset Value on empty Text</MudSwitch> <MudSwitch @bind-Checked="coerceText" Color="Color.Secondary">Coerce Text to Value</MudSwitch> <MudSwitch @bind-Checked="coerceValue" Color="Color.Tertiary">Coerce Value to Text (if not found)</MudSwitch> </MudItem> </MudGrid>