How to pass childcontent to a component in a bunit test

22 Views Asked by At

My component allows for childcontent with a parameter:

[Parameter]
public RenderFragment ChildContent { get { return m_ChildContent; } set { m_ChildContent = value; } }

The value is then used in the following way:

    <CascadingValue Value="this" Name="PopupParent" IsFixed="true">
      @ChildContent
    </CascadingValue>

Child content can be passed on:

    <ContainerComponent>
      <ChildComponent></ChildComponent>
    </ContainerComponent>

However, when used in a bunit test the ChildContent section is left empty:

        var popup = Render(@<ContainerComponent Visible="true"><ChildComponent /></ContainerComponent>);

Or in a C# file the whole markup remains empty:

      var ctx = new TestContext();
      var childContent = ctx.RenderComponent<ChildComponent>();
      var container = ctx.RenderComponent<ContainerComponent>(parameters => parameters
        .AddChildContent(childContent.Markup)
      );

Note that the childContent.Markup does have a bunch of content.

What is the correct way of doing this?

0

There are 0 best solutions below