Skip to content

Commit 38d84d6

Browse files
committed
fix: Custom elements with attributes throw exception
1 parent f8bb1c2 commit 38d84d6

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Custom elements with attributes throw `ArgumentException` with `MarkupMatches`. Reported by [@candritzky](https://github.com/candritzky). Fixed by [@linkdotnet](https://github.com/linkdotnet).
912

1013
### Changed
1114

src/bunit.web/Diffing/BlazorDiffingHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AngleSharp.Diffing.Core;
2+
using AngleSharp.Dom;
23
using AngleSharp.Html.Dom;
34

45
namespace Bunit.Diffing;
@@ -33,7 +34,7 @@ internal static IEnumerable<Comparison> UnknownElementMatch(
3334
SourceCollection testSources)
3435
{
3536
var lastMatchedTestNodeIndex = -1;
36-
foreach (var control in controlSources.GetUnmatched())
37+
foreach (var control in controlSources.GetUnmatched().Where(c => c.Node is IElement))
3738
{
3839
var comparison = TryFindMatchingNodes(control, testSources, lastMatchedTestNodeIndex + 1);
3940
if (comparison.HasValue)
@@ -46,7 +47,7 @@ internal static IEnumerable<Comparison> UnknownElementMatch(
4647

4748
private static Comparison? TryFindMatchingNodes(in ComparisonSource control, SourceCollection testSources, int startIndex)
4849
{
49-
foreach (var test in testSources.GetUnmatched(startIndex))
50+
foreach (var test in testSources.GetUnmatched(startIndex).Where(t => t.Node is IElement))
5051
{
5152
if (control.Node is IHtmlUnknownElement
5253
|| test.Node is IHtmlUnknownElement
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="main">
2+
<my-button emphasis="primary-highlight" disabled>Add new<my-icon slot="icon" size="s32"></my-icon></my-button>
3+
</div>

tests/bunit.web.tests/Asserting/MarkupMatchesAssertExtensionsTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,18 @@ public void Test015()
137137
// in a known context (e.g. <svg> or <foreignObject>)
138138
path.MarkupMatches("<path />");
139139
}
140+
141+
[Fact(DisplayName = "Werid")]
142+
public void Test016()
143+
{
144+
const string expectedMarkup = @"<div class=""main"">
145+
<my-button emphasis=""primary-highlight"" disabled>Add new<my-icon slot=""icon"" size=""s32""></my-icon></my-button>
146+
</div>
147+
";
148+
149+
// Act
150+
var chart = RenderComponent<CustomElementWithAttribute>();
151+
152+
chart.MarkupMatches(expectedMarkup);
153+
}
140154
}

0 commit comments

Comments
 (0)