Skip to content

Commit 663f5a5

Browse files
committed
test: 增加单元测试
1 parent 9f16fb4 commit 663f5a5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/UnitTest/Components/ButtonTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Microsoft.AspNetCore.Components.Web;
77
using Microsoft.Extensions.Localization;
8+
using System;
89

910
namespace UnitTest.Components;
1011

@@ -495,4 +496,30 @@ public async Task ToogleButton_Ok()
495496
Assert.True(clickWithoutRender);
496497
Assert.True(clicked);
497498
}
499+
500+
[Fact]
501+
public async Task ToggleButton_IsAsync()
502+
{
503+
var active = false;
504+
var tcs = new TaskCompletionSource();
505+
var cut = Context.RenderComponent<ToggleButton>(pb =>
506+
{
507+
pb.Add(a => a.IsAsync, true);
508+
pb.Add(a => a.Icon, "fa-solid fa-test");
509+
pb.Add(a => a.Text, "toggle-button");
510+
pb.Add(a => a.OnClick, async () =>
511+
{
512+
await Task.Delay(100);
513+
});
514+
pb.Add(a => a.OnToggleAsync, isActive =>
515+
{
516+
active = isActive;
517+
tcs.TrySetResult();
518+
return Task.CompletedTask;
519+
});
520+
});
521+
var button = cut.Find("button");
522+
await cut.InvokeAsync(() => button.Click());
523+
await tcs.Task;
524+
}
498525
}

0 commit comments

Comments
 (0)