-
-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Description
Several issues are related to SetParametersAsync, but I am unsure whether they are the same as mine, so I tried creating a new incident.
Describe the bug
When a component has SetParametersAsync then BuildRenderTree is not invoked.
Example:
Testing this component:
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
namespace ClassLibrary1;
public class ComponentWithAsyncSetParameters : ComponentBase
{
public override async Task SetParametersAsync(ParameterView parameters)
{
await Task.Delay(1000);
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
}
public class ComponentWithoutAsyncSetParameters : ComponentBase
{
public override Task SetParametersAsync(ParameterView parameters)
{
return Task.CompletedTask;
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
}
public class ComponentWithoutSetParameters : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
}With this test:
using Bunit;
using ClassLibrary1;
namespace TestProject1;
public sealed class UnitTest1 : TestContext
{
[Fact]
public void TestComponentWithAsyncSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithAsyncSetParameters>();
component.MarkupMatches(expected);
}
[Fact]
public void TestComponentWithoutAsyncSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithoutAsyncSetParameters>();
component.MarkupMatches(expected);
}
[Fact]
public void TestComponentWithoutSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithoutSetParameters>();
component.MarkupMatches(expected);
}
}Bunit.HtmlEqualException: HTML comparison failed.
Bunit.HtmlEqualException
HTML comparison failed.
The following errors were found:
1: The element at h1(0) is missing.
Actual HTML:
Expected HTML:
<h1>HEADER TEXT</h1>
at Bunit.MarkupMatchesAssertExtensions.MarkupMatches(INodeList actual, INodeList expected, String userMessage) in /_/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs:line 238
at Bunit.MarkupMatchesAssertExtensions.MarkupMatches(IRenderedFragment actual, String expected, String userMessage) in /_/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs:line 114
at TestProject1.UnitTest1.TestComponentWithoutAsyncSetParameters() in C:\Users\Mihails Kuzmins\source\repos\ClassLibrary1\TestProject1\UnitTest1.cs:line 23
at InvokeStub_UnitTest1.TestComponentWithoutAsyncSetParameters(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Expected behavior:
BuildRenderTree is invoked, and the valid HTML is rendered
Version info:
- bUnit version: 1.38.5
- .NET Runtime and Blazor version: net9.0; 9.0.3
- OS type and version: Windows 10.0.26100.3624
Metadata
Metadata
Assignees
Labels
No labels

