Skip to content

Commit e1fc069

Browse files
committed
fix: Fixed sample in docs and added more details
1 parent a923fa2 commit e1fc069

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
@code {
1+
@inherits TestContext
2+
3+
@code {
24
[Fact]
35
public void Test()
46
{
5-
using var ctx = new TestContext();
67
var currentValue = string.Empty;
78

8-
var cut = ctx.Render(@<TwoWayBinding @bind-Value="currentValue"></TwoWayBinding>);
9+
var cut = Render(@<TwoWayBinding @bind-Value="currentValue"></TwoWayBinding>);
910
}
1011
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ The example uses the `Bind` method to setup two-way binding between the `Value`
404404
[!code-cshtml[TwoWayBindingTest.razor](../../../samples/tests/razor/TwoWayBindingTest.razor)]
405405

406406
The example uses the standard `@bind-Value` directive in Blazor to set up two way binding between the `Value` parameter and `ValueChanged` parameter and the local variable in the test method (`currentValue`).
407+
408+
> [!WARNING]
409+
> When using `@bind` in conjunction with razor test-files the razor component should **not** inherit from `ComponentBase` (which is the default). The simplest solution would be to inherit from `TestContext` (as seen in the example above) which also brings the benefits as described on top of this page. For **NUnit** and **MSTest** check out the section "Remove boilerplate code from tests" on the <xref:writing-tests> page.
407410
***
408411

409412
## Further Reading

0 commit comments

Comments
 (0)