How to render SectionContent in tests? #1383
-
I have layout with SectionOutlet. On particular page (TestPage component) I use SectionContent to display some html.
markup does not contain SectionContent. How can you test content on the SectionContent block on the page? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The <SectionContent SectionName="bUnit">
<button>Click me</button>
</SectionContent> That button will not be part of your components HTML/Markup/RenderTree. The If you want to check certain things you can access the var cut = RenderComponent<MyComponent>();
var section = cut.FindComponent<SectionContent>();
var content = section.Instance.ChildContent;
section.Instance.SectionId.Should().Be("bUnit")
content.Should().NotBeNull();
// Here we are taking what is inside the SectionContent and render it
var childContent = Render(content);
childContent.Find("button").TextContent.Should().Be("Click Me"); |
Beta Was this translation helpful? Give feedback.
The
SectionContent
element itself doesn't render anything. It is a mere "placeholder" for theSectionOutlet
. So while in your code you can do something like:That button will not be part of your components HTML/Markup/RenderTree. The
SectionContent
just "holds" that so calledRenderFragment
.If you want to check certain things you can access the
ChildContent
and render that separately: