Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@formname attribute always causes an error: System.InvalidOperationException : Invalid element frame type 'NamedEvent' #1438

Closed
suzu2469 opened this issue Apr 9, 2024 · 2 comments
Labels
investigate This issue require further investigation before closing.

Comments

@suzu2469
Copy link

suzu2469 commented Apr 9, 2024

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

<h1>Sample</h1>

<form method="post" @formname="sample-form">
	<button type="submit">Submit</button>
</form>

With this test:

@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

@kato1628
Copy link

kato1628 commented Apr 9, 2024

I had the same issue in my environment.

@egil egil added the investigate This issue require further investigation before closing. label Apr 9, 2024
@egil
Copy link
Member

egil commented Apr 9, 2024

Hey, thanks for reporting this. We will take a look ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate This issue require further investigation before closing.
Projects
None yet
Development

No branches or pull requests

3 participants