Skip to content

Commit e0ca487

Browse files
committed
test: 增加单元测试
1 parent 81f9f68 commit e0ca487

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

test/UnitTest/Components/LayoutTest.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,14 @@ public async Task OnUpdateAsync_Ok()
528528
}
529529

530530
[Fact]
531-
public void HandlerException_Ok()
531+
public void IHandlerException_Ok()
532532
{
533533
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
534534
{
535535
pb.Add(a => a.EnableErrorLogger, true);
536536
pb.AddChildContent<Layout>(pb =>
537537
{
538+
// 按钮触发异常
538539
pb.Add(a => a.Main, new RenderFragment(builder =>
539540
{
540541
builder.OpenComponent<Button>(0);
@@ -552,9 +553,31 @@ public void HandlerException_Ok()
552553
var button = cut.Find("button");
553554
cut.InvokeAsync(() => button.Click());
554555
cut.Contains("<div class=\"error-stack\">");
556+
cut.Contains("class=\"layout\"");
555557
Context.DisposeComponents();
556558
}
557559

560+
[Fact]
561+
public void ErrorLogger_LifeCycle()
562+
{
563+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
564+
{
565+
pb.Add(a => a.EnableErrorLogger, true);
566+
pb.AddChildContent<Layout>(pb =>
567+
{
568+
pb.Add(a => a.UseTabSet, false);
569+
// 按钮触发异常
570+
pb.Add(a => a.Main, new RenderFragment(builder =>
571+
{
572+
builder.OpenComponent<MockPage>(0);
573+
builder.CloseComponent();
574+
}));
575+
});
576+
});
577+
cut.Contains("<div class=\"error-stack\">");
578+
cut.Contains("class=\"layout\"");
579+
}
580+
558581
[Fact]
559582
public void CollapseBarTemplate_Ok()
560583
{
@@ -600,3 +623,15 @@ public void Authorized_Ok()
600623
Context.DisposeComponents();
601624
}
602625
}
626+
627+
class MockPage : ComponentBase
628+
{
629+
protected override void OnInitialized()
630+
{
631+
var a = 1;
632+
var b = 0;
633+
634+
// 触发生命周期内异常
635+
var c = a / b;
636+
}
637+
}

0 commit comments

Comments
 (0)