Skip to content

Commit

Permalink
Added additional test for testing changes to properties in components
Browse files Browse the repository at this point in the history
  • Loading branch information
egil committed May 8, 2020
1 parent 0969f9d commit fbf0b2c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bunit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.89
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{A5D7B605-02D8-468C-9BDF-864CF93B12F9}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{A5D7B605-02D8-468C-9BDF-864CF93B12F9}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
..\CHANGELOG.md = ..\CHANGELOG.md
Expand Down Expand Up @@ -37,7 +37,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "web", "web", "{8606217F-762
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xunit", "xunit", "{679F372E-AB97-4AA3-8400-6EC870555B28}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{785D7644-18F2-45E4-9B30-016ADB7AB9E3}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{785D7644-18F2-45E4-9B30-016ADB7AB9E3}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\CI-CD-Docs.yml = ..\.github\workflows\CI-CD-Docs.yml
..\.github\workflows\CI.yml = ..\.github\workflows\CI.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<button id="tick" @onclick="Tick">Tick</button>
<button id="tock" @onclick="Tock">Tock</button>
@code {
private TaskCompletionSource<object?> _tcs = new TaskCompletionSource<object?>();
public int Counter;

private Task Tick()
{
Counter++;
return _tcs.Task.ContinueWith(t => { Counter++; });
}

private void Tock()
{
_tcs.TrySetResult(null);
}
}
18 changes: 18 additions & 0 deletions src/bunit.web.tests/Rendering/RenderWaitingHelperExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,23 @@ public void Test100()

cut.Find("#state").TextContent.ShouldBe("Stopped");
}

[Fact(DisplayName = "WaitForState can detect async changes to properties in the CUT")]
public void Test200()
{
var cut = RenderComponent<AsyncRenderChangesProperty>();
cut.Instance.Counter.ShouldBe(0);

// Clicking 'tick' changes the counter, and starts a task
cut.Find("#tick").Click();
cut.Instance.Counter.ShouldBe(1);

// Clicking 'tock' completes the task, which updates the counter
// This click causes two renders, thus something is needed to await here.
cut.Find("#tock").Click();
cut.WaitForState(() => cut.Instance.Counter == 2);

cut.Instance.Counter.ShouldBe(2);
}
}
}

0 comments on commit fbf0b2c

Please sign in to comment.