Skip to content

Commit e4befc2

Browse files
linkdotnetegil
andauthored
docs: Add limitation for rendering a RenderFragment (#1288)
Co-authored-by: Egil Hansen <[email protected]>
1 parent c1d5cd2 commit e4befc2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/site/docs/providing-input/passing-parameters-to-components.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,30 @@ The solution is to inherit from bUnits `TestContext` instead, i.e.:
442442
}
443443
```
444444

445+
## Limitations of rendering a `RenderFragment` inside a test
446+
447+
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.
448+
```razor
449+
@inherits TestContext
450+
451+
@code {
452+
[Fact]
453+
public void Button_clicked_string_gets_updated()
454+
{
455+
var output = string.Empty;
456+
var cut = Render(@<button @onclick='@(() => output = "Success")'>@output</button>);
457+
458+
cut.Find("button").Click();
459+
460+
// This will pass, as events are triggered and the function get executed
461+
output.ShouldBe("Success");
462+
463+
// This will fail, as the markup will not get updated
464+
cut.Find("button").TextContent.ShouldBe("Success");
465+
}
466+
}
467+
```
468+
445469
## Further Reading
446470

447471
- <xref:inject-services>

0 commit comments

Comments
 (0)