Skip to content

Commit

Permalink
failing test to prove the re-rendered element issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsauber committed Nov 13, 2023
1 parent b6f0be8 commit 2a282ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/bunit.testassets/BlazorE2E/LabelQueryComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
@((MarkupString) $"""<{htmlElement} aria-labelledby="{htmlElement}-with-aria-labelledby"></{htmlElement}>""")
}

@* Testing we get back the re-rendered element *@
<label for="re-rendered-element">Re-rendered Element</label>
<input id="re-rendered-element" @bind="@_count" />
<button id="increment-button" @onclick="IncrementCount">Click</button>

@code {
readonly List<string> htmlElementsThatCanHaveALabel = new()
{
Expand All @@ -44,4 +49,7 @@
"output",
"progress",
};

private int _count;
public void IncrementCount() => _count++;
}
12 changes: 12 additions & 0 deletions tests/bunit.web.query.tests/Labels/LabelQueryExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ public void Test006(string htmlElementWithLabel)
input.NodeName.ShouldBe(htmlElementWithLabel, StringCompareShould.IgnoreCase);
input.GetAttribute("aria-labelledby").ShouldBe($"{htmlElementWithLabel}-with-aria-labelledby");
}

[Fact(DisplayName = "Should reflect latest value when component re-renders")]
public void Test007()
{
var cut = RenderComponent<LabelQueryComponent>();

var input = cut.FindByLabelText("Re-rendered Element");
input.GetAttribute("value").ShouldBe("0");

cut.Find("#increment-button").Click();
input.GetAttribute("value").ShouldBe("1");
}
}

0 comments on commit 2a282ca

Please sign in to comment.