Skip to content

Commit 2a282ca

Browse files
committed
failing test to prove the re-rendered element issue
1 parent b6f0be8 commit 2a282ca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/bunit.testassets/BlazorE2E/LabelQueryComponent.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
@((MarkupString) $"""<{htmlElement} aria-labelledby="{htmlElement}-with-aria-labelledby"></{htmlElement}>""")
3434
}
3535

36+
@* Testing we get back the re-rendered element *@
37+
<label for="re-rendered-element">Re-rendered Element</label>
38+
<input id="re-rendered-element" @bind="@_count" />
39+
<button id="increment-button" @onclick="IncrementCount">Click</button>
40+
3641
@code {
3742
readonly List<string> htmlElementsThatCanHaveALabel = new()
3843
{
@@ -44,4 +49,7 @@
4449
"output",
4550
"progress",
4651
};
52+
53+
private int _count;
54+
public void IncrementCount() => _count++;
4755
}

tests/bunit.web.query.tests/Labels/LabelQueryExtensionsTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,16 @@ public void Test006(string htmlElementWithLabel)
8585
input.NodeName.ShouldBe(htmlElementWithLabel, StringCompareShould.IgnoreCase);
8686
input.GetAttribute("aria-labelledby").ShouldBe($"{htmlElementWithLabel}-with-aria-labelledby");
8787
}
88+
89+
[Fact(DisplayName = "Should reflect latest value when component re-renders")]
90+
public void Test007()
91+
{
92+
var cut = RenderComponent<LabelQueryComponent>();
93+
94+
var input = cut.FindByLabelText("Re-rendered Element");
95+
input.GetAttribute("value").ShouldBe("0");
96+
97+
cut.Find("#increment-button").Click();
98+
input.GetAttribute("value").ShouldBe("1");
99+
}
88100
}

0 commit comments

Comments
 (0)