Class TestContext
A test context is a factory that makes it possible to create components under tests.
Implements
Inherited Members
Namespace: Bunit
Assembly: Bunit.Web.dll
Syntax
public class TestContext : TestContextBase, IDisposable
Constructors
| Improve this Doc View SourceTestContext()
Creates a new instance of the TestContext class.
Declaration
public TestContext()
Properties
| Improve this Doc View SourceJSInterop
Gets bUnits JSInterop, that allows setting up handlers for Microsoft.JSInterop.IJSRuntime.InvokeAsync``1(System.String,System.Object[]) invocations that components under tests will issue during testing. It also makes it possible to verify that the invocations has happened as expected.
Declaration
public BunitJSInterop JSInterop { get; }
Property Value
Type | Description |
---|---|
BunitJSInterop |
Methods
| Improve this Doc View SourceBuildRenderTree(RenderTreeBuilder)
Dummy method required to allow Blazor's compiler to generate C# from .razor files.
Declaration
protected virtual void BuildRenderTree(RenderTreeBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder | builder |
Render(RenderFragment)
Renders the renderFragment
and returns it as a IRenderedFragment.
Declaration
public virtual IRenderedFragment Render(RenderFragment renderFragment)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Components.RenderFragment | renderFragment | The render fragment to render. |
Returns
Type | Description |
---|---|
IRenderedFragment | The IRenderedFragment. |
Render<TComponent>(RenderFragment)
Renders the renderFragment
and returns the first TComponent
in the resulting render tree.
Declaration
public virtual IRenderedComponent<TComponent> Render<TComponent>(RenderFragment renderFragment)
where TComponent : IComponent
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Components.RenderFragment | renderFragment | The render fragment to render. |
Returns
Type | Description |
---|---|
IRenderedComponent<TComponent> |
Type Parameters
Name | Description |
---|---|
TComponent | The type of component to find in the render tree. |
Remarks
Calling this method is equivalent to calling Render(renderFragment).FindComponent<TComponent>()
.
RenderComponent<TComponent>(ComponentParameter[])
Instantiates and performs a first render of a component of type TComponent
.
Declaration
public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters)
where TComponent : IComponent
Parameters
Type | Name | Description |
---|---|---|
ComponentParameter[] | parameters | Parameters to pass to the component when it is rendered |
Returns
Type | Description |
---|---|
IRenderedComponent<TComponent> | The rendered |
Type Parameters
Name | Description |
---|---|
TComponent | Type of the component to render |
RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>)
Instantiates and performs a first render of a component of type TComponent
.
Declaration
public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>> parameterBuilder)
where TComponent : IComponent
Parameters
Type | Name | Description |
---|---|---|
System.Action<ComponentParameterCollectionBuilder<TComponent>> | parameterBuilder | The ComponentParameterBuilder action to add type safe parameters to pass to the component when it is rendered |
Returns
Type | Description |
---|---|
IRenderedComponent<TComponent> | The rendered |
Type Parameters
Name | Description |
---|---|
TComponent | Type of the component to render |