-
-
Notifications
You must be signed in to change notification settings - Fork 364
fix(BootstrapBlazorErrorBoundary): improve BuildRenderTree logic to render error or fallback content #6114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ArgoZhang
merged 11 commits into
dotnetcore:main
from
flyliononline:fix-bootstrap-blazor-error-boundary
May 30, 2025
Merged
fix(BootstrapBlazorErrorBoundary): improve BuildRenderTree logic to render error or fallback content #6114
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
85ca185
fix(BootstrapBlazorErrorBoundary): improve BuildRenderTree logic to r…
flyliononline 9bbfc09
Merge branch 'main' into fix-bootstrap-blazor-error-boundary
ArgoZhang 169b68a
Merge branch 'main' into fix-bootstrap-blazor-error-boundary
ArgoZhang 8d3e9e5
test: 更新单元测试
ArgoZhang 77a5590
doc: 更新全局异常示例
ArgoZhang eaad170
feat: 增加基类重置方法
ArgoZhang 789ecf4
refactor: 消除警告信息
ArgoZhang 1d8e8ce
chore: bump version 9.7.1-beta01
ArgoZhang 3f864f0
Merge remote-tracking branch 'gitee.com/feat-bump' into fix-bootstrap…
ArgoZhang ca87f46
doc: 更新文档
ArgoZhang 78fa59f
refactor: 恢复模板代码
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/UnitTest/Components/BootstrapBlazorErrorBoundaryTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace UnitTest.Components; | ||
|
|
||
| public class BootstrapBlazorErrorBoundaryTest : BootstrapBlazorTestBase | ||
| { | ||
| // 1. Test rendering of child content when there is no exception | ||
| [Fact] | ||
| public void ShouldRenderChildContent_WhenNoException() | ||
| { | ||
| var cut = Context.RenderComponent<BootstrapBlazorErrorBoundary>(parameters => parameters | ||
| .AddChildContent("<p>Normal Content</p>") | ||
| ); | ||
| cut.MarkupMatches("<p>Normal Content</p>"); | ||
| } | ||
|
|
||
| // 2. Test rendering custom error content when an exception is thrown and ErrorContent is set | ||
| [Fact] | ||
| public void ShouldRenderCustomErrorContent_WhenExceptionOccurs() | ||
| { | ||
| var errorContentRendered = false; | ||
|
|
||
| var cut = Context.RenderComponent<BootstrapBlazorErrorBoundary>(parameters => parameters | ||
| .Add(p => p.ErrorContent, ex => builder => | ||
| { | ||
| errorContentRendered = true; | ||
| builder.OpenElement(0, "div"); | ||
| builder.AddAttribute(1, "class", "custom-error"); | ||
| builder.AddContent(2, $"Custom error caught: {ex.Message}"); | ||
| builder.CloseElement(); | ||
| }) | ||
| .AddChildContent<ExceptionThrowingComponent>() | ||
| ); | ||
|
|
||
| cut.MarkupMatches("""<div class="custom-error">Custom error caught: Boom!</div>"""); | ||
| Assert.True(errorContentRendered); | ||
| } | ||
|
|
||
| // 3. Test rendering default error content when an exception is thrown and ErrorContent is null | ||
| [Fact] | ||
| public void ShouldRenderDefaultExceptionContent_WhenExceptionOccurs_AndErrorContentIsNull() | ||
| { | ||
| var cut = Context.RenderComponent<BootstrapBlazorErrorBoundary>(parameters => parameters | ||
| .AddChildContent<ExceptionThrowingComponent>() | ||
| ); | ||
| Assert.Contains("Boom!", cut.Markup); | ||
| } | ||
|
|
||
| private class ExceptionThrowingComponent : ComponentBase | ||
| { | ||
| protected override void OnInitialized() | ||
| { | ||
| throw new InvalidOperationException("Boom!"); | ||
| } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.