How to render SectionContent in tests? #1383
Answered
by
linkdotnet
AntonBaluev
asked this question in
Q&A
|
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? |
Answered by
linkdotnet
Feb 18, 2024
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"); |
1 reply
Answer selected by
AntonBaluev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
SectionContentelement 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
SectionContentjust "holds" that so calledRenderFragment.If you want to check certain things you can access the
ChildContentand render that separately: