bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
Describe the bug
I get an error when trying to test a component that contains a form with the @formname attribute
If I remove the @formname attribute, the error no longer occurs.
Here is a simple, reproducible repository
https://github.com/suzu2469/bunit-sample-tests
Example:
Testing this component: TestProduct.razor
@inherits TestContext
@code {
[Fact]
public void TestProductSampleTest() {
var cut = RenderComponent<TestProduct>();
Assert.NotNull(cut.Instance);
}
}
Results in this output:
[xUnit.net 00:00:00.25] SampleApp.TestProductTests.TestProductSampleTest [FAIL]
失敗 SampleApp.TestProductTests.TestProductSampleTest [168 ms]
エラー メッセージ:
System.InvalidOperationException : Invalid element frame type 'NamedEvent'.
スタック トレース:
at Bunit.Htmlizer.RenderCore(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 123
at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position, Int32 maxElements) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 82
at Bunit.Htmlizer.RenderChildren(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position, Int32 maxElements) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 236
at Bunit.Htmlizer.RenderElement(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 190
at Bunit.Htmlizer.RenderCore(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 104
at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position, Int32 maxElements) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 82
at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 137
at Bunit.Htmlizer.RenderCore(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 116
at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position, Int32 maxElements) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 82
at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 137
at Bunit.Htmlizer.RenderCore(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 116
at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext context, ReadOnlySpan`1 frames, Int32 position, Int32 maxElements) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 82
at Bunit.Htmlizer.GetHtml(Int32 componentId, RenderTreeFrameDictionary framesCollection) in /_/src/bunit.web/Rendering/Internal/Htmlizer.cs:line 62
at Bunit.Rendering.RenderedFragment.UpdateMarkup(RenderTreeFrameDictionary framesCollection) in /_/src/bunit.web/Rendering/RenderedFragment.cs:line 164
at Bunit.Rendering.RenderedFragment.Bunit.IRenderedFragmentBase.OnRender(RenderEvent renderEvent) in /_/src/bunit.web/Rendering/RenderedFragment.cs:line 142
at Bunit.Rendering.TestRenderer.ApplyRenderEvent(RenderEvent renderEvent) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 401
at Bunit.Rendering.TestRenderer.UpdateDisplayAsync(RenderBatch& renderBatch) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 309
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
at Bunit.Rendering.TestRenderer.AssertNoUnhandledExceptions() in /_/src/bunit.core/Rendering/TestRenderer.cs:line 629
at Bunit.Rendering.TestRenderer.Render[TResult](RenderFragment renderFragment, Func`2 activator) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 480
at Bunit.Rendering.TestRenderer.RenderFragment(RenderFragment renderFragment) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 101
at Bunit.Extensions.TestContextBaseRenderExtensions.RenderInsideRenderTree(TestContextBase testContext, RenderFragment renderFragment) in /_/src/bunit.core/Extensions/TestContextBaseRenderExtensions.cs:line 43
at Bunit.Extensions.TestContextBaseRenderExtensions.RenderInsideRenderTree[TComponent](TestContextBase testContext, RenderFragment renderFragment) in /_/src/bunit.core/Extensions/TestContextBaseRenderExtensions.cs:line 23
at Bunit.TestContext.Render[TComponent](RenderFragment renderFragment) in /_/src/bunit.web/TestContext.cs:line 68
at Bunit.TestContext.RenderComponent[TComponent](Action`1 parameterBuilder) in /_/src/bunit.web/TestContext.cs:line 54
at SampleApp.TestProductTests.TestProductSampleTest() in /Users/souma_suzuki/Desktop/SampleApp/TestProductTests.razor:line 6
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
失敗! -失敗: 1、合格: 0、スキップ: 0、合計: 1、期間: < 1 ms - SampleApp.dll (net8.0)
Expected behavior:
The test succeeds without error.
Version info:
bUnit version: 1.27.17
.NET Runtime and Blazor version: 8.0.203
OS type and version: MacOS 13.2.1(22D68)
Additional context:
I did a dotnet test immediately after starting a new Codespaces with the above repositories and the results were the same
Describe the bug I get an error when trying to test a component that contains a
form
with the@formname
attribute If I remove the@formname
attribute, the error no longer occurs. Here is a simple, reproducible repository https://github.com/suzu2469/bunit-sample-testsExample: Testing this component: TestProduct.razor
With this test:
Results in this output:
Expected behavior:
The test succeeds without error.
Version info:
Additional context:
I did a
dotnet test
immediately after starting a new Codespaces with the above repositories and the results were the same