Interface IMockerBlazorTestHelpers<T>
Helper methods for locating, rendering, and interacting with Blazor components in FastMoq-based bUnit tests.
Namespace: FastMoq.Web.Blazor.Interfaces
Assembly: FastMoq.Web.dll
Syntax
public interface IMockerBlazorTestHelpers<T> where T : ComponentBase
Type Parameters
| Name | Description |
|---|---|
| T | The root component type under test. |
Methods
ClickButton(IElement, Func<bool>, TimeSpan?)
Clicks the button element.
Declaration
IMockerBlazorTestHelpers<T> ClickButton(IElement button, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IElement | button | The button. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
ClickButton(Func<IElement, bool>, Func<bool>, TimeSpan?)
Clicks the button element.
Declaration
IMockerBlazorTestHelpers<T> ClickButton(Func<IElement, bool> cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IElement, bool> | cssSelector | The CSS selector. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | cssSelector |
ClickButton(string, Func<bool>, TimeSpan?)
Clicks the button element.
Declaration
IMockerBlazorTestHelpers<T> ClickButton(string cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
ClickButton<TComponent>(string, Func<bool>, IRenderedComponent<TComponent>, TimeSpan?)
Clicks the button element.
Declaration
IMockerBlazorTestHelpers<T> ClickButton<TComponent>(string cssSelector, Func<bool> waitFunc, IRenderedComponent<TComponent> startingComponent, TimeSpan? waitTimeout = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| Func<bool> | waitFunc | The wait function. |
| IRenderedComponent<TComponent> | startingComponent | The starting component. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
ClickButton<TComponent>(string, Func<bool>, TimeSpan?)
Clicks the button element.
Declaration
IMockerBlazorTestHelpers<T> ClickButton<TComponent>(string cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | cssSelector |
ClickDropdownItem<TComponent>(IRenderedComponent<TComponent>, string, string, Func<bool>)
Clicks the dropdown item.
Declaration
IRenderedComponent<TComponent> ClickDropdownItem<TComponent>(IRenderedComponent<TComponent> component, string cssSelector, string propName, Func<bool> waitFunc) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| IRenderedComponent<TComponent> | component | The component. |
| string | cssSelector | The CSS selector. |
| string | propName | Name of the property. |
| Func<bool> | waitFunc | The wait function. |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<TComponent> | IRenderedComponent<TComponent>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
ClickDropdownItem<TComponent>(string, Func<bool>, string)
Clicks the dropdown item.
Declaration
IRenderedComponent<TComponent> ClickDropdownItem<TComponent>(string propName, Func<bool> waitFunc, string cssDropdownSelector = "a.dropdown-item") where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| string | propName | Name of the property. |
| Func<bool> | waitFunc | The wait function. |
| string | cssDropdownSelector | The CSS dropdown selector. |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<TComponent> | IRenderedComponent<DropdownList<TKey, TValue>>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
FindAllByTag(string)
Finds all by tag.
Declaration
IEnumerable<IElement> FindAllByTag(string tagName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tagName | Name of the tag. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IElement> | IEnumerable<IElement>. |
FindById(string)
Finds the by identifier.
Declaration
IElement? FindById(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The identifier. |
Returns
| Type | Description |
|---|---|
| IElement | IElement. |
GetComponent<TComponent>()
Gets the component.
Declaration
IRenderedComponent<TComponent> GetComponent<TComponent>() where TComponent : class, IComponent
Returns
| Type | Description |
|---|---|
| IRenderedComponent<TComponent> | IRenderedComponent<TComponent>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Examples
var comp = GetComponent<FetchData>();
GetComponent<TComponent>(Func<IElement, bool>)
Gets the component.
Declaration
IRenderedComponent<TComponent> GetComponent<TComponent>(Func<IElement, bool> predicate) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IElement, bool> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<TComponent> | IRenderedComponent<TComponent>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Examples
var comp = GetComponent<FetchData>(element => element.InnerHtml.Contains("hello"));
GetComponent<TComponent>(Func<IRenderedComponent<TComponent>, bool>)
Gets the component.
Declaration
IRenderedComponent<TComponent> GetComponent<TComponent>(Func<IRenderedComponent<TComponent>, bool> predicate) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IRenderedComponent<TComponent>, bool> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<TComponent> | IRenderedComponent<TComponent>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Examples
Filter rendered components by component state.
var comp = GetComponent<FetchData>(x => x.ComponentId == 1234);
Filter rendered components by instance values.
var comp = GetComponent<FetchData>(x => x.Instance.IsRunning);
GetComponents<TComponent>(Func<IElement, bool>?)
Gets the components.
Declaration
List<IRenderedComponent<TComponent>> GetComponents<TComponent>(Func<IElement, bool>? predicate = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IElement, bool> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| List<IRenderedComponent<TComponent>> | List<IRenderedComponent<TComponent>>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t of type. |
Examples
var list = GetComponents<FetchData>(element => element.InnerHtml.Contains("hello"));
GetComponents<TComponent>(Func<IRenderedComponent<TComponent>, bool>?)
Gets the components.
Declaration
IReadOnlyList<IRenderedComponent<TComponent>> GetComponents<TComponent>(Func<IRenderedComponent<TComponent>, bool>? predicate = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IRenderedComponent<TComponent>, bool> | predicate | The where function. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<IRenderedComponent<TComponent>> | List<IRenderedComponent<TComponent>>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t of type. |
Examples
Get all rendered FetchData components with a matching component id.
var list = GetComponents<FetchData>(x => x.ComponentId == 1234);
Get all rendered FetchData components with a matching instance state.
var list = GetComponents<FetchData>(x => x.Instance.IsRunning);
GetInjections(Type)
Gets the injections.
Declaration
IEnumerable<PropertyInfo> GetInjections(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description |
|---|---|
| IEnumerable<PropertyInfo> | IEnumerable<PropertyInfo>. |
GetInjections(Type, Type)
Gets the injections.
Declaration
IEnumerable<PropertyInfo> GetInjections(Type type, Type injectAttribute)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| Type | injectAttribute | The inject attribute. |
Returns
| Type | Description |
|---|---|
| IEnumerable<PropertyInfo> | IEnumerable<PropertyInfo>. |
GetInjections<TComponent>()
Gets the injections.
Declaration
IEnumerable<PropertyInfo> GetInjections<TComponent>()
Returns
| Type | Description |
|---|---|
| IEnumerable<PropertyInfo> | IEnumerable<PropertyInfo>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
InjectComponent(Type)
Injects the component.
Declaration
IMockerBlazorTestHelpers<T> InjectComponent(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
InjectComponent(Type, Type)
Injects the component.
Declaration
IMockerBlazorTestHelpers<T> InjectComponent(Type type, Type injectAttribute)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| Type | injectAttribute | The inject attribute. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
InjectComponent<TComponent>()
Injects the component.
Declaration
IMockerBlazorTestHelpers<T> InjectComponent<TComponent>()
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
InjectComponent<TComponent, TInjectAttribute>()
Injects the component.
Declaration
IMockerBlazorTestHelpers<T> InjectComponent<TComponent, TInjectAttribute>() where TInjectAttribute : Attribute
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
| TInjectAttribute | The type of the t inject attribute. |
IsExists(string, bool)
Determines whether the specified CSS selector is exists.
Declaration
bool IsExists(string cssSelector, bool throwOnNotExist = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| bool | throwOnNotExist | if set to |
Returns
| Type | Description |
|---|---|
| bool |
|
RenderComponent(Action<ComponentParameterCollectionBuilder<T>>, bool)
Renders the component. If the component is already rendered, it will act like a stateChanged.
Declaration
IRenderedComponent<T> RenderComponent(Action<ComponentParameterCollectionBuilder<T>> parameterBuilder, bool forceNew = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<ComponentParameterCollectionBuilder<T>> | parameterBuilder | The parameter builder. |
| bool | forceNew | if set to |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<T> | IRenderedComponent<T>. |
Remarks
Use this overload for direct parameter changes. If the test needs to persist or mutate named cascading parameters,
update RenderParameters and call RenderComponent(bool) so the helper can choose the compatible
rerender path.
Examples
Render again with parameters without losing context.
RenderComponent(b => b.Add(x => x.Title, "Reviewed Orders"));
Force an initial render with parameters.
RenderComponent(b => b.Add(x => x.Title, "Reviewed Orders"), true);
RenderComponent(bool)
Renders the component. If the component is already rendered, it will act like a stateChanged.
Declaration
IRenderedComponent<T> RenderComponent(bool forceNew = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | forceNew | if set to |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<T> | IRenderedComponent<T>. |
Examples
Render again without losing context. This honors any parameters already configured in RenderParameters.
RenderComponent();
Force a fresh initial render.
RenderComponent(true);
SetAutoComplete(string, string, Func<bool>, string)
Sets the automatic complete.
Declaration
Task SetAutoComplete(string cssSelector, string filterText, Func<bool> waitFunc, string itemCssSelector = ".b-is-autocomplete-suggestion")
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| string | filterText | The filter text. |
| Func<bool> | waitFunc | The wait function. |
| string | itemCssSelector | The item CSS selector. |
Returns
| Type | Description |
|---|---|
| Task | Task. |
SetElementCheck<TComponent>(string, bool, Func<bool>, TimeSpan?, IRenderedComponent<IComponent>?)
Sets the element check.
Declaration
IMockerBlazorTestHelpers<T> SetElementCheck<TComponent>(string cssSelector, bool isChecked, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedComponent<IComponent>? startingPoint = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| bool | isChecked | if set to |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
| IRenderedComponent<IComponent> | startingPoint | An optional rendered child component used to scope the lookup to a nested subtree. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Examples
var secondaryEditor = GetComponent<OrderMigrationEditor>(x => x.Instance.EditorId == "secondary");
SetElementCheck<OrderMigrationEditor>("input.include-archived", true, () => secondaryEditor.Instance.IncludeArchived, startingPoint: secondaryEditor);
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | cssSelector |
| ElementNotFoundException |
SetElementSwitch<TComponent>(string, bool, Func<bool>, TimeSpan?, IRenderedComponent<IComponent>?)
Sets the element switch.
Declaration
IMockerBlazorTestHelpers<T> SetElementSwitch<TComponent>(string cssSelector, bool isChecked, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedComponent<IComponent>? startingPoint = null) where TComponent : class, IComponent
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| bool | isChecked | if set to |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
| IRenderedComponent<IComponent> | startingPoint | An optional rendered child component used to scope the lookup to a nested subtree. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Type Parameters
| Name | Description |
|---|---|
| TComponent | The type of the t component. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | cssSelector |
SetElementText(IElement, string, Func<bool>, TimeSpan?)
Sets the element text.
Declaration
IMockerBlazorTestHelpers<T> SetElementText(IElement element, string text, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IElement | element | The element. |
| string | text | The text. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
SetElementText(string, string, Func<bool>, TimeSpan?, IRenderedComponent<IComponent>?)
Sets the element text.
Declaration
IMockerBlazorTestHelpers<T> SetElementText(string cssSelector, string text, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedComponent<IComponent>? startingPoint = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| string | text | The text. |
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
| IRenderedComponent<IComponent> | startingPoint | An optional rendered child component used to scope the lookup to a nested subtree. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
Examples
var secondaryEditor = GetComponent<OrderMigrationEditor>(x => x.Instance.EditorId == "secondary");
SetElementText("input.order-filter", "approved", () => secondaryEditor.Instance.FilterText == "approved", startingPoint: secondaryEditor);
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | cssSelector |
WaitDelay(TimeSpan?)
Waits the delay time. Use only when absolutely needed. Prefer use of WaitForState, WaitForExists, or
WaitForNotExists.
Declaration
IMockerBlazorTestHelpers<T> WaitDelay(TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
WaitForExists(string, TimeSpan?)
Waits for exists.
Declaration
IMockerBlazorTestHelpers<T> WaitForExists(string cssSelector, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
WaitForNotExists(string, TimeSpan?)
Waits for not exists.
Declaration
IMockerBlazorTestHelpers<T> WaitForNotExists(string cssSelector, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cssSelector | The CSS selector. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | IMockerBlazorTestHelpers<T>. |
WaitForState(Func<bool>, TimeSpan?)
Waits for state.
Declaration
IMockerBlazorTestHelpers<T> WaitForState(Func<bool> waitFunc, TimeSpan? waitTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | waitFunc | The wait function. |
| TimeSpan? | waitTimeout | The wait timeout. |
Returns
| Type | Description |
|---|---|
| IMockerBlazorTestHelpers<T> | The current helper instance. |