A testing library for Blazor components. Get started testing Blazor components at https://bunit.dev
await element.FocusAsync()
, the code never continues. I am not really interested in catching focus event, but I don't understand why it gets stuck there and never continues. For net3.1 I have a JSInterop.SetupVoid("myfocusevent", _ => true).SetVoidResult()
but I cannot find anywhere how to handle FocusAsync()
.
Anyway, I tried. It didn't work. But informed me that Bunit.JSInvokeCountExpectedException : VerifyInvoke failed: "Blazor._internal.domWrapper.focus" was not called the expected number of times.
. So I added this line:
JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();
Solved my problem. But this is not intended, right?
await Task.Delay
.@using AntDesign.Core.JsInterop.Modules.Components
@inherits AntDesignTestBase
@code {
public Select_Tags_Tests()
{
JSInterop.Setup<AntDesign.JsInterop.DomRect>(JSInteropConstants.GetBoundingClientRect, _ => true)
.SetResult(new AntDesign.JsInterop.DomRect());
JSInterop.Setup<HtmlElement>(JSInteropConstants.GetDomInfo, _ => true)
.SetResult(new HtmlElement());
JSInterop.SetupVoid(JSInteropConstants.AddPreventKeys, _ => true);
JSInterop.SetupVoid(JSInteropConstants.AddElementTo, _ => true);
#if !NET6_0_OR_GREATER
JSInterop.SetupVoid(JSInteropConstants.Focus, _ => true).SetVoidResult();
#else
JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();
#endif
}
[Fact]
public async Task Single_tag_creation() //issue #1645
{
//Arrange
JSInterop.Setup<OverlayPosition>(JSInteropConstants.OverlayComponentHelper.AddOverlayToContainer, _ => true)
.SetResult(new OverlayPosition() { Top = 0, Left = 0, ZIndex = 5000, Placement = Placement.BottomLeft });
var cut = Render<AntDesign.Select<string, string>>(
@<AntDesign.Select Mode="tags"
TItemValue="string"
TItem="string"
EnableSearch>
<SelectOptions>
<SelectOption TItemValue="string" TItem="string" Value="@("1")" Label="1" />
</SelectOptions>
</AntDesign.Select>
);
//Act
//overlay.
var input = cut.Find("input.ant-select-selection-search-input");
input.Input("A"); //await element.FocusAsync() is called by Select here
cut.WaitForState(() => cut.Instance.ActiveOption is not null);
await Task.Delay(100);
input.KeyUp("ENTER");
await Task.Delay(1);
input.Input("B");
await Task.Delay(1);
input.KeyUp("ENTER");
await Task.Delay(1);
input.Input("C");
await Task.Delay(1);
input.KeyUp("ENTER");
await Task.Delay(1);
var addedTags = cut.FindAll("span.ant-select-selection-item-content")
.Where(d => d.TextContent.Trim() == "B");
//Assert
addedTags.Should().HaveCount(1);
}
}
input.Input("A")
- await element.FocusAsync()
is called by Select here
JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult()
SetupVoids
not registering and wanting an interface (smth like IJSVoidResult
but I am not sure). Did you get that kind of error?
<MudTable @ref="filteredTable" Items="states" Filter="new Func<string, bool>(FilterFunc)" RowsPerPage="@rows">
<ToolBarContent>
<MudText>Filtered Item Count: @FilteredItemCount</MudText>
<MudSpacer />
<MudTextField id="searchString" @bind-Value="searchString" Placeholder="Search"></MudTextField>
</ToolBarContent>
<RowTemplate>
<MudTd>@context</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager />
</PagerContent>
</MudTable>
<MudButton OnClick="@(() => ButtonClick())">Toggle Rows</MudButton>
var testComponent = Context.RenderComponent<TablePagerChangeRowsPerPageTest>();
var table = testComponent.FindComponent<MudTable<string>>().Instance;
testComponent.Find("button").Click();