Skip to content

Commit 64c0c72

Browse files
committed
test: 增加 TabItemContent 单元测试
1 parent 596a502 commit 64c0c72

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/UnitTest/Components/ErrorLoggerTest.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,46 @@ public void ErrorContent_Ok()
185185
cut.InvokeAsync(() => button.Click());
186186
cut.Contains("Attempted to divide by zero.error_content_template");
187187
}
188+
189+
[Fact]
190+
public async Task TabItem_Error()
191+
{
192+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
193+
{
194+
pb.AddChildContent<Tab>(pb =>
195+
{
196+
pb.AddChildContent<TabItem>(pb =>
197+
{
198+
pb.Add(a => a.Text, "Text1");
199+
pb.Add(a => a.ChildContent, builder => builder.AddContent(0, RenderButton()));
200+
});
201+
});
202+
});
203+
204+
var button = cut.Find("button");
205+
await cut.InvokeAsync(() => button.Click());
206+
207+
// 页面不崩溃,由弹窗显示异常信息
208+
cut.Contains("<div class=\"error-stack\">TimeStamp:");
209+
210+
// 单元测试覆盖 TabItemContent Dispose 方法
211+
var handler = Activator.CreateInstance("BootstrapBlazor", "BootstrapBlazor.Components.TabItemContent");
212+
Assert.NotNull(handler);
213+
var content = handler.Unwrap();
214+
Assert.NotNull(content);
215+
216+
Assert.IsType<IDisposable>(content, exactMatch: false);
217+
((IDisposable)content).Dispose();
218+
}
219+
220+
private RenderFragment RenderButton() => builder =>
221+
{
222+
builder.OpenComponent<Button>(0);
223+
builder.AddAttribute(2, nameof(Button.OnClick), EventCallback.Factory.Create<MouseEventArgs>(this, e =>
224+
{
225+
var a = 0;
226+
_ = 1 / a;
227+
}));
228+
builder.CloseComponent();
229+
};
188230
}

0 commit comments

Comments
 (0)