BlazorTestingLibrary 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazorTestingLibrary --version 1.0.2                
NuGet\Install-Package BlazorTestingLibrary -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorTestingLibrary" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorTestingLibrary --version 1.0.2                
#r "nuget: BlazorTestingLibrary, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 490 9/29/2022
1.0.2 386 9/29/2022
1.0.1 397 9/29/2022
1.0.0 412 9/28/2022