Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to test Blazor MudSelect with bUnit?

$
0
0

I am struggling with testing a MudSelect component with bUnit.

Example.razor

@using MudBlazor<MudSelect @bind-Value="_selectedValue"           Label="Age">    @for(var i = 0; i < 100; i++)    {        var age = i;<MudSelectItem T="int?" Value="@age">@age</MudSelectItem>    }</MudSelect>@code {    private int? _selectedValue;}

Wrapper.razor

@using MudBlazor<MudPopoverProvider/><Example />

ExampleTests.cs

using FluentAssertions;using MudBlazor;using MudBlazor.Services;namespace App.UnitTests.Example;public class ExampleTests : TestContext{    public ExampleTests()    {        Services.AddMudServices();        JSInterop.SetupVoid("mudPopover.initialize", _ => true);        JSInterop.SetupVoid("mudKeyInterceptor.connect", _ => true);        JSInterop.Setup<int>("mudpopoverHelper.countProviders");        JSInterop.SetupVoid("mudKeyInterceptor.updatekey", _ => true);    }    [Fact]    public void TestMudSelect()    {        var cut = RenderComponent<Wrapper>();        var select = cut.FindComponent<MudSelect<int?>>();        var menu = cut.Find("div.mud-popover");        var input = cut.Find("div.mud-input-control");        menu.ClassList.Should().Contain("select-popover-class");        select.Instance.Value.Should().BeNull();        cut.WaitForAssertion(() => cut.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));        input.Click();        menu.ClassList.Should().Contain("mud-popover-open");        cut.WaitForAssertion(() => cut.FindAll("div.mud-list-item").Count.Should().BeGreaterThan(0));        var items = cut.FindAll("div.mud-list-item").ToArray();        items[1].Click();    }}

The above is inspired by MudBlazors's tests, and this discussion.

No matter what I try there are never any list items rendered. I am completely stuck now.

Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>