BlazorTestingLibrary 1.0.2
See the version list below for details.
dotnet add package BlazorTestingLibrary --version 1.0.2
NuGet\Install-Package BlazorTestingLibrary -Version 1.0.2
<PackageReference Include="BlazorTestingLibrary" Version="1.0.2" />
paket add BlazorTestingLibrary --version 1.0.2
#r "nuget: BlazorTestingLibrary, 1.0.2"
// Install BlazorTestingLibrary as a Cake Addin #addin nuget:?package=BlazorTestingLibrary&version=1.0.2 // Install BlazorTestingLibrary as a Cake Tool #tool nuget:?package=BlazorTestingLibrary&version=1.0.2
BlazorTestingLibrary
A (better?) React-like testing approach for Blazor apps. This is still a work in progress but it's useable 😃
Quickstart Example
using BlazorTestingLibrary;
using Bunit;
using FluentAssertions;
using Xunit;
...
[Fact]
public void SubmittingAValidForm()
{
using var context = new TestContext();
var component = context.RenderComponent<ExampleForm>();
var forenameInput = component.FindByLabelText("Forename:");
forenameInput.Change("John");
var surnameInput = component.FindByLabelText("Surname:");
surnameInput.Change("Smith");
var emailInput = component.FindByLabelText("Email Address:");
emailInput.Change("john.smith@developer.com");
var submitButton = component.FindByText("Submit");
submitButton.Click();
component.FindByText("Your form is Submitted").Should().NotBeNull();
}
Search Methods
FindByText
Searches for a given text string in the DOM and returns the first element that contains it. Throws if there is more than one element found or nothing is found.
FindAllByText
Searches for a given text string in the DOM and returns all instances of elements that contain it. Throws if nothing is found.
FindById
Searches for an element with a given id. Throws if there is more than one element found or nothing is found.
FindByLabelText
Searches for an input with a particular label attached to it via for
attribute.
Throws if there is more than one element found or nothing is found.
Verify Methods
ShouldHaveClass
Asserts that a given element has a class.
ShouldHaveId
Asserts that a given element has an id.
Waiting for a condition (WaitFor)
Sometimes you may need to wait for something to happen, which you can do with
WaitFor(Action action, int timeout = 5000)
. This will perform an action
until it doesn't throw or the timeout is met. A ActionTimedOutException
will be thrown
if the timeout is reached.
Libraries Used
- FluentAssertions
- BUnit
- RichardSzalay.MockHttp
Footnotes
This library currently only targets net6.0
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- bunit (>= 1.9.8)
- FluentAssertions (>= 6.7.0)
- RichardSzalay.MockHttp (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.