Table of Contents

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

renderedComponent IRenderedComponent<TComponent>

The rendered fragment to wait for renders from and assert against.

assertion Action

The verification or assertion to perform.

timeout TimeSpan?

The maximum time to attempt the verification.

Returns

Task

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

renderedComponent IRenderedComponent<TComponent>

The rendered fragment to wait for renders from and assert against.

assertion Action

The verification or assertion to perform.

timeout TimeSpan?

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

renderedComponent IRenderedComponent<IComponent>

The rendered component to find the component in.

timeout TimeSpan?

The maximum time to wait for the element to appear.

Returns

IRenderedComponent<TComponent>

See IRenderedComponent<TComponent>.

Type Parameters

TComponent

The 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

renderedComponent IRenderedComponent<IComponent>

The rendered component in which to search for instances of the specified component.

matchComponentCount int

The minimum amount component instances to wait for.

timeout TimeSpan?

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

TComponent

The 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

renderedComponent IRenderedComponent<IComponent>

The rendered component in which to search for instances of the specified component.

timeout TimeSpan?

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

TComponent

The 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for the element.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for the element.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

matchElementCount int

The exact number of elements to that the cssSelector should match.

Returns

Task<IReadOnlyList<IElement>>

The IReadOnlyList<T>.

Type Parameters

TComponent

Exceptions

WaitForFailedException

Thrown if no elements is found matching the cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

matchElementCount int

The exact number of elements to that the cssSelector should match.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

matchElementCount int

The exact number of elements to that the cssSelector should match.

Returns

IReadOnlyList<IElement>

The IReadOnlyList<T>.

Type Parameters

TComponent

Exceptions

WaitForFailedException

Thrown if no elements is found matching the cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

matchElementCount int

The exact number of elements to that the cssSelector should match.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component find the matching element in.

cssSelector string

The CSS selector to use to search for elements.

timeout TimeSpan

The 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 cssSelector within 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component to attempt to verify state against.

statePredicate Func<bool>

The predicate to invoke after each render, which must returns true when the desired state has been reached.

timeout TimeSpan?

The maximum time to wait for the desired state.

Returns

Task

Type Parameters

TComponent

Exceptions

WaitForFailedException

Thrown if the statePredicate throw 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

renderedComponent IRenderedComponent<TComponent>

The render fragment or component to attempt to verify state against.

statePredicate Func<bool>

The predicate to invoke after each render, which must returns true when the desired state has been reached.

timeout TimeSpan?

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 statePredicate throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.

.NET Foundation

Supported by the .NET Foundation.