Add E2E test showing we can pass properties to child components and auto re-render them on change
This commit is contained in:
parent
5981002a40
commit
4f496f649a
|
|
@ -113,6 +113,22 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
childComponentWrapper.FindElement(By.TagName("p")).Text);
|
childComponentWrapper.FindElement(By.TagName("p")).Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ChildComponentsRerenderWhenPropertiesChanged()
|
||||||
|
{
|
||||||
|
var appElement = MountTestComponent<CounterComponentUsingChild>();
|
||||||
|
|
||||||
|
Assert.Equal(
|
||||||
|
"Current count: 0",
|
||||||
|
appElement.FindElement(By.TagName("p")).Text);
|
||||||
|
|
||||||
|
appElement.FindElement(By.TagName("button")).Click();
|
||||||
|
|
||||||
|
Assert.Equal(
|
||||||
|
"Current count: 1",
|
||||||
|
appElement.FindElement(By.TagName("p")).Text);
|
||||||
|
}
|
||||||
|
|
||||||
private IWebElement MountTestComponent<TComponent>() where TComponent: IComponent
|
private IWebElement MountTestComponent<TComponent>() where TComponent: IComponent
|
||||||
{
|
{
|
||||||
var componentTypeName = typeof(TComponent).FullName;
|
var componentTypeName = typeof(TComponent).FullName;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<h1>Counter</h1>
|
||||||
|
<p>Current count: <c:MessageComponent Message="@currentCount.ToString()" /></p>
|
||||||
|
<button @onclick(IncrementCount)>Click me</button>
|
||||||
|
|
||||||
|
@functions {
|
||||||
|
int currentCount = 0;
|
||||||
|
|
||||||
|
void IncrementCount()
|
||||||
|
{
|
||||||
|
currentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<span style="color: red">@Message</span>
|
||||||
|
@functions {
|
||||||
|
public string Message { get; set; }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue