We can use the unit test concepts and frameworks that we've seen in Chapter 13, Understanding How Testing Works, but Microsoft (again, with Steve Sanderson) has also been working on something to make our lives easier if we're dealing with Blazor.
Steve has a project, available on GitHub at https://github.com/SteveSandersonMS/BlazorUnitTestingPrototype, which contains a prototype of a unit testing framework that can be used to easily test Blazor components. It's called Microsoft.AspNetCore.Components.Testing and, unfortunately, it is still unavailable on NuGet, but you can clone the code and use it directly. Then, you can write code like this:
varhost=newTestHost();
//Counter is a Blazor component
varcomponent=host.AddComponent<Counter>();
//count is a named element inside Counter
var count = component.Find("#count");
Assert.NotNull(count);
var button = component.Find("button");
Assert.NotNull(button);
button.Click(...