Skip to content

Commit e6e2407

Browse files
committed
test: 增加单元测试
1 parent bc82d78 commit e6e2407

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using Microsoft.AspNetCore.Components.Rendering;
7-
using Microsoft.Extensions.Configuration;
87
using Microsoft.Extensions.Localization;
98
using Microsoft.Extensions.Logging;
109

test/UnitTest/Components/ErrorLoggerTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,35 @@ public void Root_Ok()
127127
cut.InvokeAsync(() => button.Click());
128128
Assert.NotNull(exception);
129129
}
130+
131+
[Fact]
132+
public void ErrorContent_Ok()
133+
{
134+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
135+
{
136+
pb.Add(a => a.EnableErrorLogger, true);
137+
pb.Add(a => a.ShowToast, false);
138+
pb.AddChildContent<Button>(pb =>
139+
{
140+
pb.Add(b => b.OnClick, () =>
141+
{
142+
var a = 0;
143+
_ = 1 / a;
144+
});
145+
});
146+
});
147+
148+
var errorLogger = cut.FindComponent<ErrorLogger>();
149+
errorLogger.SetParametersAndRender(pb =>
150+
{
151+
pb.Add(a => a.ErrorContent, new RenderFragment<Exception>(ex => builder =>
152+
{
153+
builder.AddContent(0, ex.Message);
154+
builder.AddContent(1, "error_content_template");
155+
}));
156+
});
157+
var button = cut.Find("button");
158+
cut.InvokeAsync(() => button.Click());
159+
cut.Contains("Attempted to divide by zero.error_content_template");
160+
}
130161
}

0 commit comments

Comments
 (0)