File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
src/BootstrapBlazor/Components/ErrorLogger Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 44// Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 55
66using Microsoft . AspNetCore . Components . Rendering ;
7- using Microsoft . Extensions . Configuration ;
87using Microsoft . Extensions . Localization ;
98using Microsoft . Extensions . Logging ;
109
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments