Skip to content
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

docs: Add limitation for rendering a RenderFragment #1288

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/site/docs/providing-input/passing-parameters-to-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,30 @@ The solution is to inherit from bUnits `TestContext` instead, i.e.:
}
```

## Limitations of rendering a `RenderFragment` inside a test

When rendering a `RenderFragment` using the <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> method, the created <xref:Bunit.IRenderedFragment> is static. This means that it will not re-render even if events are triggered.
```razor
@inherits TestContext

@code {
[Fact]
public void Button_clicked_string_gets_updated()
{
var output = string.Empty;
var cut = Render(@<button @onclick='@(() => output = "Success")'>@output</button>);

cut.Find("button").Click();

// This will pass, as events are triggered and the function get executed
output.ShouldBe("Success");

// This will fail, as the markup will not get updated
cut.Find("button").TextContent.ShouldBe("Success");
}
}
```

## Further Reading

- <xref:inject-services>
Loading