Skip to content

Commit 41f8ece

Browse files
authored
Merge branch 'master' into dev
2 parents 865ea40 + 3df4dec commit 41f8ece

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

sample/tests/RazorTestComponents/Components/AlertRazorTest.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits TestComponentBase
1+
@inherits TestComponentBase
22

33
@code {
44
MockJsRuntimeInvokeHandler MockJsRuntime { get; set; } = default!;

sample/tests/Tests/Components/AlertTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using Egil.RazorComponents.Testing.Asserting;
44
using Egil.RazorComponents.Testing.EventDispatchExtensions;

sample/tests/_Imports.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using Microsoft.AspNetCore.Components.Web
1+
@using Microsoft.AspNetCore.Components.Web
22
@using Microsoft.Extensions.DependencyInjection
33

44
@using Egil.RazorComponents.Testing

src/Asserting/MarkupMatchesAssertExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ public static void MarkupMatches(this INode actual, string expected, string? use
106106
MarkupMatches(actual, expectedNodes, userMessage);
107107
}
108108

109+
/// <summary>
110+
/// Verifies that the <paramref name="actual"/> <see cref="INode"/> matches
111+
/// the <paramref name="expected"/> markup, using the <see cref="HtmlComparer"/>
112+
/// type.
113+
/// </summary>
114+
/// <exception cref="HtmlEqualException">Thrown when the <paramref name="actual"/> markup does not match the <paramref name="expected"/> markup.</exception>
115+
/// <param name="actual">The node to verify.</param>
116+
/// <param name="expected">The expected markup.</param>
117+
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
118+
public static void MarkupMatches(this INode actual, string expected, string? userMessage = null)
119+
{
120+
if (actual is null) throw new ArgumentNullException(nameof(actual));
121+
122+
INodeList expectedNodes;
123+
if (actual.GetHtmlParser() is { } parser)
124+
{
125+
expectedNodes = parser.Parse(expected);
126+
}
127+
else
128+
{
129+
using var newParser = new TestHtmlParser();
130+
expectedNodes = newParser.Parse(expected);
131+
}
132+
MarkupMatches(actual, expectedNodes, userMessage);
133+
}
134+
109135
/// <summary>
110136
/// Verifies that the <paramref name="actual"/> <see cref="INodeList"/> matches
111137
/// the <paramref name="expected"/> markup, using the <see cref="HtmlComparer"/>

0 commit comments

Comments
 (0)