Class RenderedComponentWaitForHelperExtensions
- Namespace
- Bunit
- Assembly
- bunit.dll
Provides extension methods for waiting on components within a rendered Blazor component.
public static class RenderedComponentWaitForHelperExtensions
- Inheritance
-
RenderedComponentWaitForHelperExtensions
- Inherited Members
Methods
WaitForAssertionAsync<TComponent>(IRenderedComponent<TComponent>, Action, TimeSpan?)
Wait until the provided assertion passes (i.e. does not throw an
exception), or the timeout is reached (default is one second).
The assertion is attempted initially, and then each time the renderedComponent renders.
[AssertionMethod]
public static Task WaitForAssertionAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, Action assertion, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The rendered fragment to wait for renders from and assert against.
assertionActionThe verification or assertion to perform.
timeoutTimeSpan?The maximum time to attempt the verification.
Returns
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if the timeout has been reached. See the inner exception to see the captured assertion exception.
WaitForAssertion<TComponent>(IRenderedComponent<TComponent>, Action, TimeSpan?)
Wait until the provided assertion passes (i.e. does not throw an
exception), or the timeout is reached (default is one second).
The assertion is attempted initially, and then each time the renderedComponent renders.
[AssertionMethod]
public static void WaitForAssertion<TComponent>(this IRenderedComponent<TComponent> renderedComponent, Action assertion, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The rendered fragment to wait for renders from and assert against.
assertionActionThe verification or assertion to perform.
timeoutTimeSpan?The maximum time to attempt the verification.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if the timeout has been reached. See the inner exception to see the captured assertion exception.
WaitForComponent<TComponent>(IRenderedComponent<IComponent>, TimeSpan?)
Waits until the specified component is rendered in the DOM.
public static IRenderedComponent<TComponent> WaitForComponent<TComponent>(this IRenderedComponent<IComponent> renderedComponent, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<IComponent>The rendered component to find the component in.
timeoutTimeSpan?The maximum time to wait for the element to appear.
Returns
- IRenderedComponent<TComponent>
Type Parameters
TComponentThe target component type to wait for.
WaitForComponents<TComponent>(IRenderedComponent<IComponent>, int, TimeSpan?)
Waits until the specified number of components are rendered in the DOM and returns their instances.
public static IReadOnlyCollection<IRenderedComponent<TComponent>> WaitForComponents<TComponent>(this IRenderedComponent<IComponent> renderedComponent, int matchComponentCount, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<IComponent>The rendered component in which to search for instances of the specified component.
matchComponentCountintThe minimum amount component instances to wait for.
timeoutTimeSpan?The maximum time to wait for the components to appear. Defaults to no specific timeout if not provided.
Returns
- IReadOnlyCollection<IRenderedComponent<TComponent>>
A read-only collection of IRenderedComponent<TComponent> instances representing the found components.
Type Parameters
TComponentThe target component type to wait for.
WaitForComponents<TComponent>(IRenderedComponent<IComponent>, TimeSpan?)
Waits until the specified component is rendered in the DOM and returns all instances of that component when the first instance is found.
public static IReadOnlyCollection<IRenderedComponent<TComponent>> WaitForComponents<TComponent>(this IRenderedComponent<IComponent> renderedComponent, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<IComponent>The rendered component in which to search for instances of the specified component.
timeoutTimeSpan?The maximum time to wait for the components to appear. Defaults to no specific timeout if not provided.
Returns
- IReadOnlyCollection<IRenderedComponent<TComponent>>
A read-only collection of IRenderedComponent<TComponent> instances representing the found components.
Type Parameters
TComponentThe target component type to wait for.
WaitForElementAsync<TComponent>(IRenderedComponent<TComponent>, string)
Wait until an element matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static Task<IElement> WaitForElementAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for the element.
Returns
- Task<IElement>
The AngleSharp.Dom.IElement.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout. See the inner exception for details.
WaitForElementAsync<TComponent>(IRenderedComponent<TComponent>, string, TimeSpan)
Wait until an element matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static Task<IElement> WaitForElementAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for the element.
timeoutTimeSpanThe maximum time to wait for the element to appear.
Returns
- Task<IElement>
The AngleSharp.Dom.IElement.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout. See the inner exception for details.
WaitForElement<TComponent>(IRenderedComponent<TComponent>, string)
Wait until an element matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static IElement WaitForElement<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for the element.
Returns
- IElement
The AngleSharp.Dom.IElement.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout. See the inner exception for details.
WaitForElement<TComponent>(IRenderedComponent<TComponent>, string, TimeSpan)
Wait until an element matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static IElement WaitForElement<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for the element.
timeoutTimeSpanThe maximum time to wait for the element to appear.
Returns
- IElement
The AngleSharp.Dom.IElement.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout. See the inner exception for details.
WaitForElementsAsync<TComponent>(IRenderedComponent<TComponent>, string)
Wait until at least one element matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static Task<IReadOnlyList<IElement>> WaitForElementsAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
Returns
- Task<IReadOnlyList<IElement>>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElementsAsync<TComponent>(IRenderedComponent<TComponent>, string, int)
Wait until exactly matchElementCount element(s) matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static Task<IReadOnlyList<IElement>> WaitForElementsAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, int matchElementCount) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.
Returns
- Task<IReadOnlyList<IElement>>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElementsAsync<TComponent>(IRenderedComponent<TComponent>, string, int, TimeSpan)
Wait until exactly matchElementCount element(s) matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static Task<IReadOnlyList<IElement>> WaitForElementsAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, int matchElementCount, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- Task<IReadOnlyList<IElement>>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElementsAsync<TComponent>(IRenderedComponent<TComponent>, string, TimeSpan)
Wait until at least one element matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static Task<IReadOnlyList<IElement>> WaitForElementsAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- Task<IReadOnlyList<IElement>>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElements<TComponent>(IRenderedComponent<TComponent>, string)
Wait until at least one element matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static IReadOnlyList<IElement> WaitForElements<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
Returns
- IReadOnlyList<IElement>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElements<TComponent>(IRenderedComponent<TComponent>, string, int)
Wait until exactly matchElementCount element(s) matching the cssSelector exists in the renderedComponent,
or the timeout is reached (default is one second).
public static IReadOnlyList<IElement> WaitForElements<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, int matchElementCount) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.
Returns
- IReadOnlyList<IElement>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElements<TComponent>(IRenderedComponent<TComponent>, string, int, TimeSpan)
Wait until exactly matchElementCount element(s) matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static IReadOnlyList<IElement> WaitForElements<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, int matchElementCount, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- IReadOnlyList<IElement>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForElements<TComponent>(IRenderedComponent<TComponent>, string, TimeSpan)
Wait until at least one element matching the cssSelector exists in the renderedComponent,
or the timeout is reached.
public static IReadOnlyList<IElement> WaitForElements<TComponent>(this IRenderedComponent<TComponent> renderedComponent, string cssSelector, TimeSpan timeout) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- IReadOnlyList<IElement>
The IReadOnlyList<T>.
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin the default timeout.
WaitForStateAsync<TComponent>(IRenderedComponent<TComponent>, Func<bool>, TimeSpan?)
Wait until the provided statePredicate action returns true,
or the timeout is reached (default is one second).
The statePredicate is evaluated initially, and then each time
the renderedComponent renders.
public static Task WaitForStateAsync<TComponent>(this IRenderedComponent<TComponent> renderedComponent, Func<bool> statePredicate, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component to attempt to verify state against.
statePredicateFunc<bool>The predicate to invoke after each render, which must returns
truewhen the desired state has been reached.timeoutTimeSpan?The maximum time to wait for the desired state.
Returns
Type Parameters
TComponent
Exceptions
- WaitForFailedException
Thrown if the
statePredicatethrow an exception during invocation, or if the timeout has been reached. See the inner exception for details.
WaitForState<TComponent>(IRenderedComponent<TComponent>, Func<bool>, TimeSpan?)
Wait until the provided statePredicate action returns true,
or the timeout is reached (default is one second).
The statePredicate is evaluated initially, and then each time
the renderedComponent renders.
public static void WaitForState<TComponent>(this IRenderedComponent<TComponent> renderedComponent, Func<bool> statePredicate, TimeSpan? timeout = null) where TComponent : IComponent
Parameters
renderedComponentIRenderedComponent<TComponent>The render fragment or component to attempt to verify state against.
statePredicateFunc<bool>The predicate to invoke after each render, which must returns
truewhen the desired state has been reached.timeoutTimeSpan?The maximum time to wait for the desired state.
Type Parameters
TComponent
Remarks
If a debugger is attached the timeout is set to InfiniteTimeSpan, giving the possibility to debug without the timeout triggering.
Exceptions
- WaitForFailedException
Thrown if the
statePredicatethrow an exception during invocation, or if the timeout has been reached. See the inner exception for details.