You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
6
6
7
7
## [Unreleased]
8
8
9
+
### Added
10
+
11
+
- New overloads to WaitForHelpers to have async assertions and predicates. Reported by [@radmorecameron](https://github.com/radmorecameron) in #1833. Fixed by [@linkdotnet](https://github.com/linkdotnet).
Copy file name to clipboardExpand all lines: src/bunit/Extensions/WaitForHelpers/RenderedComponentWaitForHelperExtensions.WaitForState.cs
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,31 @@ public static async Task WaitForStateAsync<TComponent>(this IRenderedComponent<T
56
56
awaitwaiter.WaitTask;
57
57
}
58
58
59
+
/// <summary>
60
+
/// Wait until the provided asynchronous <paramref name="statePredicate"/> returns true,
61
+
/// or the <paramref name="timeout"/> is reached (default is one second).
62
+
///
63
+
/// The <paramref name="statePredicate"/> is evaluated initially, and then each time
64
+
/// the <paramref name="renderedComponent"/> renders.
65
+
/// </summary>
66
+
/// <param name="renderedComponent">The render fragment or component to attempt to verify state against.</param>
67
+
/// <param name="statePredicate">The asynchronous predicate to invoke after each render, which must return <c>true</c> when the desired state has been reached.</param>
68
+
/// <param name="timeout">The maximum time to wait for the desired state.</param>
69
+
/// <exception cref="WaitForFailedException">Thrown if the <paramref name="statePredicate"/> throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.</exception>
70
+
/// <remarks>
71
+
/// The predicate is awaited on the renderer's dispatcher. Because awaiting yields the dispatcher,
72
+
/// a render may interleave at each <c>await</c> point, so the predicate is not guaranteed an atomic
73
+
/// view of the DOM across awaits. Use this overload when the check itself must <c>await</c> (for
74
+
/// example an async service or JavaScript interop call); prefer the synchronous <see cref="WaitForState{TComponent}(IRenderedComponent{TComponent}, Func{bool}, TimeSpan?)"/>
/// Wait until the provided asynchronous <paramref name="assertion"/> passes (i.e. does not throw an
130
+
/// exception), or the <paramref name="timeout"/> is reached (default is one second).
131
+
///
132
+
/// The <paramref name="assertion"/> is attempted initially, and then each time the <paramref name="renderedComponent"/> renders.
133
+
/// </summary>
134
+
/// <param name="renderedComponent">The rendered fragment to wait for renders from and assert against.</param>
135
+
/// <param name="assertion">The asynchronous verification or assertion to perform.</param>
136
+
/// <param name="timeout">The maximum time to attempt the verification.</param>
137
+
/// <exception cref="WaitForFailedException">Thrown if the timeout has been reached. See the inner exception to see the captured assertion exception.</exception>
138
+
/// <remarks>
139
+
/// The assertion is awaited on the renderer's dispatcher. Because awaiting yields the dispatcher,
140
+
/// a render may interleave at each <c>await</c> point, so the assertion is not guaranteed an atomic
141
+
/// view of the DOM across awaits. Use this overload when the assertion itself must <c>await</c> (for
142
+
/// example an async service or JavaScript interop call); prefer the synchronous <see cref="WaitForAssertion{TComponent}(IRenderedComponent{TComponent}, Action, TimeSpan?)"/>
Copy file name to clipboardExpand all lines: src/bunit/Extensions/WaitForHelpers/WaitForAssertionHelper.cs
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -37,4 +37,28 @@ public WaitForAssertionHelper(IRenderedComponent<TComponent> renderedComponent,
37
37
},
38
38
timeout)
39
39
{}
40
+
41
+
/// <summary>
42
+
/// Initializes a new instance of the <see cref="WaitForAssertionHelper{TComponent}"/> class,
43
+
/// which will until the provided asynchronous <paramref name="assertion"/> passes (i.e. does not throw an
44
+
/// exception), or the <paramref name="timeout"/> is reached (default is one second).
45
+
///
46
+
/// The <paramref name="assertion"/> is attempted initially, and then each time the <paramref name="renderedComponent"/> renders.
47
+
/// </summary>
48
+
/// <param name="renderedComponent">The rendered fragment to wait for renders from and assert against.</param>
49
+
/// <param name="assertion">The asynchronous verification or assertion to perform.</param>
50
+
/// <param name="timeout">The maximum time to attempt the verification.</param>
51
+
/// <remarks>
52
+
/// If a debugger is attached the timeout is set to <see cref="Timeout.InfiniteTimeSpan" />, giving the possibility to debug without the timeout triggering.
/// Initializes a new instance of the <see cref="WaitForStateHelper{TComponent}"/> class,
40
+
/// which will wait until the provided asynchronous <paramref name="statePredicate"/> returns true,
41
+
/// or the <paramref name="timeout"/> is reached (default is one second).
42
+
/// </summary>
43
+
/// <remarks>
44
+
/// The <paramref name="statePredicate"/> is evaluated initially, and then each time the <paramref name="renderedComponent"/> renders.
45
+
/// </remarks>
46
+
/// <param name="renderedComponent">The render fragment or component to attempt to verify state against.</param>
47
+
/// <param name="statePredicate">The asynchronous predicate to invoke after each render, which must return <c>true</c> when the desired state has been reached.</param>
48
+
/// <param name="timeout">The maximum time to wait for the desired state.</param>
49
+
/// <exception cref="WaitForFailedException">Thrown if the <paramref name="statePredicate"/> throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.</exception>
0 commit comments