Skip to content

Commit

Permalink
fix: Htmlizer can handle NamedEvents
Browse files Browse the repository at this point in the history
Fixes #1438
  • Loading branch information
linkdotnet committed Apr 19, 2024
1 parent f8ede16 commit 27a43f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad
### Fixed

- bUnit's built-in HTML parser did not correctly parse full HTML documents that included a <!DOCTYPE html> as the first element. Fixed by [@egil](https://github.com/egil).
- `@formname` directive led to an `InvalidOperationException` when used on a form element. Reported by [@suzu2469](https://github.com/suzu2469) in [#1438](https://github.com/bUnit-dev/bUnit/issues/1438).
Fixed by [@egil](https://github.com/egil)/[@linkdotnet](https://github.com/linkdotnet).

### Changed
- `NavigationManager` is again registered as a singleton instead of scoped.
Expand Down
4 changes: 4 additions & 0 deletions src/bunit.web/Rendering/Internal/Htmlizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ int position
case RenderTreeFrameType.ElementReferenceCapture:
case RenderTreeFrameType.ComponentReferenceCapture:
return position + 1;
#if NET8_0_OR_GREATER
case RenderTreeFrameType.NamedEvent:
return position + 1;
#endif
default:
throw new InvalidOperationException(
$"Invalid element frame type '{frame.FrameType}'."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form method="post" @formname="sample-form">
<button type="submit">Submit</button>
</form>
14 changes: 14 additions & 0 deletions tests/bunit.web.tests/Rendering/Internal/HtmlizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ public void Test003()

cut.Find("button").HasAttribute("blazor:elementreference").ShouldBeTrue();
}

#if NET8_0_OR_GREATER
[Fact(DisplayName = "Htmlizer ignores NamedEvents")]
public void Test004()
{
var cut = RenderComponent<FormNameComponent>();

cut.MarkupMatches("""
<form method="post">
<button type="submit">Submit</button>
</form>
""");
}
#endif

private sealed class Htmlizer01Component : ComponentBase
{
public ElementReference ButtomElmRef { get; set; }
Expand Down

0 comments on commit 27a43f7

Please sign in to comment.