Skip to content

Show ErrorBoundary ErrorContent #688

Answered by linkdotnet
marcoatribeiro asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @marcoatribeiro.
There are multiple ways to approach that, but let's start with the basics (if you know this already just jump to the next section).
Imagine we have this component which is almost the same as your example:

<ErrorBoundary>
    <ChildContent>
        <MyErrorComponent></MyErrorComponent>
    </ChildContent>
    <ErrorContent Context="exception">
        <p>Here could be an exception</p> 
    </ErrorContent>
</ErrorBoundary>

Where MyErrorComponent throws an Exception in OnInitialized.

We can write a test to check that:

[Fact]
public void ShouldShowErrorOnException()
{
    var cut = RenderComponent<ErrorComponent>();

    var error = cut.FindComponent<ErrorBoundary>();

    

Replies: 1 comment 1 reply

Comment options

linkdotnet
Apr 24, 2022
Maintainer Sponsor

You must be logged in to vote
1 reply
@marcoatribeiro
Comment options

Answer selected by marcoatribeiro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants