Skip to content

Testing components under HeadContent #593

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

linkdotnet
Dec 31, 2021
Maintainer Sponsor

You must be logged in to vote

Hi Steven,

With the introduction of component factories, this is probably the best solution for solving this. The simpel approach that is supported right now is something like this:

ComponentFactories.AddStub<HeadContent>();
var cut = RenderComponent<Component>(p => p .Add(s => s.Title, "Title"));

var headContent = cut.FindComponent<Stub<HeadContent>>();
var headContentChildContent = Render(headContent.Instance.Parameters.Get(p => p.ChildContent));
var metaTags = headContentChildContent.FindAll("meta");
var titleMeta = metaTags.SingleOrDefault(m => m.Attributes.Any(a => a.Name == "title"));
titleMeta.Should().NotBeNull();
titleMeta.NodeValue.Should().Be("Title");

Obviously that is very v…

Replies: 1 comment 1 reply

Comment options

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

linkdotnet Dec 31, 2021
Maintainer Author Sponsor

Answer selected by linkdotnet
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