Skip to content

Commit ecc8339

Browse files
authored
docs: add section about InvaldOperationException when using razor tests (#1281)
1 parent 96528a1 commit ecc8339

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,26 @@ There are scenarios where it is not possible or not desirable to inherit from `T
422422

423423
***
424424

425+
## Getting an `InvalidOperationException`
426+
When the razor syntax is used and the test throws the following exception:
427+
428+
> System.InvalidOperationException: The render handle is not yet assigned.
429+
430+
This usually means that the test class (Blazor component where the tests is declared in) is direclty inheriting from `ComponentBase`, as is the default for all Blazor components.
431+
432+
The solution is to inherit from bUnits `TestContext` instead, i.e.:
433+
```razor
434+
@inherits TestContext
435+
436+
@code {
437+
[Fact]
438+
public void Test1()
439+
{
440+
// test code
441+
}
442+
}
443+
```
444+
425445
## Further Reading
426446

427447
- <xref:inject-services>

0 commit comments

Comments
 (0)