feat: Add async overloads#1834
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds async delegate overloads for bUnit wait helpers, enabling WaitForStateAsync and WaitForAssertionAsync to await Func<Task<bool>> and Func<Task> checks for async assertion frameworks such as TUnit.
Changes:
- Refactors the shared wait helper pipeline to support awaited checks while preserving synchronous behavior.
- Adds public async predicate/assertion overloads and helper constructors.
- Adds tests and changelog coverage for the new overloads.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs |
Refactors wait execution to a ValueTask-based async pipeline with re-render coalescing. |
src/bunit/Extensions/WaitForHelpers/WaitForStateHelper.cs |
Adds constructor support for async state predicates. |
src/bunit/Extensions/WaitForHelpers/WaitForAssertionHelper.cs |
Adds constructor support for async assertions. |
src/bunit/Extensions/WaitForHelpers/RenderedComponentWaitForHelperExtensions.WaitForState.cs |
Exposes new public async overloads for state predicates and assertions. |
tests/bunit.tests/Extensions/WaitForHelpers/RenderedComponentWaitForHelperExtensions.cs |
Adds coverage for async wait success, timeout, exception, and dispatcher re-entry scenarios. |
CHANGELOG.md |
Documents the new async wait helper overloads under Unreleased. |
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added |
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WaitForAssertionHelper{TComponent}"/> class, | ||
| /// which will until the provided asynchronous <paramref name="assertion"/> passes (i.e. does not throw an |
| /// <param name="renderedComponent">The render fragment or component to attempt to verify state against.</param> | ||
| /// <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> | ||
| /// <param name="timeout">The maximum time to wait for the desired state.</param> | ||
| /// <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> |
| /// <param name="renderedComponent">The render fragment or component to attempt to verify state against.</param> | ||
| /// <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> | ||
| /// <param name="timeout">The maximum time to wait for the desired state.</param> | ||
| /// <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> |
|
@egil Guess you are busy - I'd merge the PR and make a preview release so the person requested can check. As it is a preview version, we can still "revert" or reshape the PR in any fashion that suites us. Hope that is fine for you. In the spirite of: Better sorry than safe ;) |
Yeah it's pretty extreme right now. Thanks for taking charge. |
Closes #1833