diff --git a/src/bunit.web/Rendering/WebTestRenderer.cs b/src/bunit.web/Rendering/WebTestRenderer.cs index 2249abf8e..0e710b50a 100644 --- a/src/bunit.web/Rendering/WebTestRenderer.cs +++ b/src/bunit.web/Rendering/WebTestRenderer.cs @@ -7,34 +7,33 @@ using Microsoft.JSInterop; #endif -namespace Bunit.Rendering +namespace Bunit.Rendering; + +/// +/// Represents a that is used when rendering +/// Blazor components for the web. +/// +public class WebTestRenderer : TestRenderer { /// - /// Represents a that is used when rendering - /// Blazor components for the web. + /// Initializes a new instance of the class. /// - public class WebTestRenderer : TestRenderer + public WebTestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory) + : base(renderedComponentActivator, services, loggerFactory) { - /// - /// Initializes a new instance of the class. - /// - public WebTestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory) - : base(renderedComponentActivator, services, loggerFactory) - { #if NET5_0_OR_GREATER - ElementReferenceContext = new WebElementReferenceContext(services.GetRequiredService()); + ElementReferenceContext = new WebElementReferenceContext(services.GetRequiredService()); #endif - } + } #if NET5_0_OR_GREATER - /// - /// Initializes a new instance of the class. - /// - public WebTestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator) - : base(renderedComponentActivator, services, loggerFactory, componentActivator) - { - ElementReferenceContext = new WebElementReferenceContext(services.GetRequiredService()); - } -#endif + /// + /// Initializes a new instance of the class. + /// + public WebTestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator) + : base(renderedComponentActivator, services, loggerFactory, componentActivator) + { + ElementReferenceContext = new WebElementReferenceContext(services.GetRequiredService()); } -} +#endif +} \ No newline at end of file diff --git a/tests/bunit.testassets/SampleComponents/LoadingComponent.razor b/tests/bunit.testassets/SampleComponents/LoadingComponent.razor new file mode 100644 index 000000000..35c9bf469 --- /dev/null +++ b/tests/bunit.testassets/SampleComponents/LoadingComponent.razor @@ -0,0 +1,12 @@ +@text +@code { + [Parameter] + public Task Task { get; set; } + + private string text = "loading"; + protected override async Task OnInitializedAsync() + { + await Task; + text = "done"; + } +} diff --git a/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor new file mode 100644 index 000000000..3596c1a60 --- /dev/null +++ b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor @@ -0,0 +1,18 @@ +@using Bunit.TestAssets.SampleComponents +@inherits TestContext + +@code { + [Fact] + public void MarkupMatchesShouldNotBeBlockedByRenderer() + { + var tcs = new TaskCompletionSource(); + + var cut = Render(@ ); + + cut.MarkupMatches(@loading); + + tcs.SetResult(true); + + cut.WaitForAssertion(() => cut.MarkupMatches(@done)); + } +}