bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
@onclick:preventDefault
attribute set. Reported by @linkdotnet. Fixed by @egil.@onclick:preventDefault
attribute. By @JelleHissink.<path>
element parsed without being inside a <svg>
element. The semantic comparer will now be able to treat those as regular elements and thus be able to compare correctly to other elements of the same type and with the same node name. By @egil.IMemoryCache
by default to the Services container. By @linkdotnet.FakeNavigationManager
to handle umlauts.This release contains a bunch of small tweaks and fixes.
StateFromJson
method to the NavigationHistory
type, to make it easy to deserialize navigation state stored as JSON during a call to NavigationManager.NavigateTo
, e.g. as seen with the new InteractiveRequestOptions
type available in .NET 7. By @linkdotnet and @egil.Added new test double FakeWebAssemblyHostEnvironment
that implements IWebAssemblyHostEnvironment
. By @KristofferStrube.
Added Bind
method to parameter builder that makes it easier to emulate the @bind-Value
syntax in C#-based tests.
When writing tests in razor files, the @bind-
directive can be directly applied like this:
<MyComponent @bind-Value="myParam"></MyComponent>
The same expression in C# syntax is more verbose like this:
RenderComponent<MyComponent>(ps => ps
.Add(c => c.Value, value)
.Add(c => c.ValueChanged, newValue => value = newValue)
.Add(c => c.ValueExpression, () => value));
With the new Bind
method this can be done in one method:
RenderComponent<MyComponent>(ps => ps
.Bind(c => c.Value, value, newValue => value = newValue, () => value));
By @linkdotnet and @egil.
Added support for NavigationLock
, which allows user code to intercept and prevent navigation. By @linkdotnet and @egil.
JSInterop.VerifyInvoke
reported the wrong number of actual invocations of a given identifier. Reported by @otori. Fixed by @linkdotnet.WaitForAssertion
method is now marked as an assertion method with the [AssertionMethod]
attribute. This makes certain analyzers like SonarSource's Tests should include assertions happy. By @egil.A race condition existed between WaitForState
/ WaitForAssertion
and FindComponents
, if the first used the latter. Reported by @rmihael, @SviatoslavK, and @RaphaelMarcouxCTRL. Fixed by @egil and @linkdotnet.
Triggering of event handlers now runs entirely inside the renderers synchronization context, avoiding race condition between elements in the DOM tree being updated by the renderer and the event triggering logic traversing the DOM tree to find event handlers to trigger. Reported by @FlukeFan. Fixed by @egil.