Skip to content

Commit 424f7b4

Browse files
committed
Docs: last bits of passing parameters
1 parent 498002b commit 424f7b4

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

docs/samples/tests/razor/AllFixtureParameters.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@inherits TestComponentBase
2+
13
<Fixture Setup=@Setup
24
SetupAsync=@SetupAsync
35
Test=@Test

docs/samples/tests/razor/AllSnapshotTestParameters.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@inherits TestComponentBase
2+
13
<SnapshotTest Setup=@Setup
24
SetupAsync=@SetupAsync
35
Description="Description of test"

docs/samples/tests/razor/FixtureWithCutAndFragments.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@inherits TestComponentBase
2+
13
<Fixture Test="...">
24
<ComponentUnderTest>
35
<!-- Razor or HTML markup goes here -->

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,25 @@ This is just regular Blazor cascading value parameter passing, which is the same
430430
431431
***
432432
433-
## Render Component Test inside other Components
433+
## Render a Component Under Test Inside Other Components
434+
435+
It is possible to nest a component under tests inside other components, if that is needed to test it. For example, to nest the `<HelloWorld>` component inside the `<Wrapper>` component, do the following:
436+
437+
# [C# test code](#tab/csharp)
438+
439+
[!code-csharp[](../../../samples/tests/xunit/NestedComponentTest.cs#L16-L28)]
440+
441+
These examples do the same thing, i.e. rendering the `<HelloWorld>` component inside the `<Wrapper>` component. What is special in both cases is the use of the `FindComponent<HelloWorld>()`, which returns a `IRenderedComponent<HelloWorld>`, which gives access to only the `<HelloWorld>` components part of the render tree, and the `<HelloWorld>` components instance.
442+
443+
# [Razor test code](#tab/razor)
444+
445+
[!code-html[](../../../samples/tests/razor/NestedComponentTest.razor#L3-)]
446+
447+
This is just regular Blazor child content parameter passing, where one component is rendered inside another, i.e. the `<HelloWorld>` component inside the `<Wrapper>` component.
448+
449+
The special thing in this case is that the `GetComponentUnderTest<HelloWorld>()` method specifies the `<HelloWorld>` component as its target instead of the outer `<Wrapper>` component. This returns a `IRenderedComponent<HelloWorld>`, which gives access to only the `<HelloWorld>` components part of the render tree, and the `<HelloWorld>` components instance.
450+
451+
***
434452
435453
## Further Reading
436454

0 commit comments

Comments
 (0)