Skip to content

How to render SectionContent in tests? #1383

Answered by linkdotnet
AntonBaluev asked this question in Q&A
Discussion options

You must be logged in to vote

The SectionContent element itself doesn't render anything. It is a mere "placeholder" for the SectionOutlet. So while in your code you can do something like:

<SectionContent SectionName="bUnit">
 <button>Click me</button>
</SectionContent>

That button will not be part of your components HTML/Markup/RenderTree. The SectionContent just "holds" that so called RenderFragment.

If you want to check certain things you can access the ChildContent and render that separately:

var cut = RenderComponent<MyComponent>();

var section = cut.FindComponent<SectionContent>();
var content = section.Instance.ChildContent;

section.Instance.SectionId.Should().Be("bUnit")
content.Should().NotBeNull();
// Here …

Replies: 1 comment 1 reply

Comment options

linkdotnet
Feb 18, 2024
Maintainer Sponsor

You must be logged in to vote
1 reply
@AntonBaluev
Comment options

Answer selected by AntonBaluev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants