Skip to content

Releases: bUnit-dev/bUnit

1.11.7

13 Oct 11:13
ac4061c
Compare
Choose a tag to compare

Added

  • Added the 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.

1.10.14

16 Sep 16:27
a0af4e1
Compare
Choose a tag to compare

Added

  • 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.

Fixed

  • JSInterop.VerifyInvoke reported the wrong number of actual invocations of a given identifier. Reported by @otori. Fixed by @linkdotnet.

1.9.8

07 Jun 11:08
482d690
Compare
Choose a tag to compare

Changed

  • 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.

Fixes

  • 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.

1.8.15

19 May 20:31
604c96f
Compare
Choose a tag to compare

Added

Changed

  • Htmlizer uses StringBuilder instead of List<string> to reduce allocations and improve render speed. By @linkdotnet.

Fixes

  • TestServiceProvider now implements IAsyncDisposable. This means TestContext.Dispose() now calls the async disposable method as well as the non-async version on the service provider. It does however not block or await the task returned, since that can lead to deadlocks.

    To await the disposal of async services registered in the TestContext.Services container, do the following:

    1. Create a new type that derives from TestContext and which implement IAsyncDisposable.
    2. In the DisposeAsync() method, call Services.DisposeAsync().
    3. Override the Dispose and have it only call Services.Dispose().

    Reported by @vedion and fixed by @egil.

1.7.7

29 Apr 17:32
9bf85db
Compare
Choose a tag to compare

Added

  • Added method SetAuthenticationType to TestAuthorizationContext to allow for custom authentication type checks. By @TimPurdum.

  • Added DisposeComponents to TestContextBase. It will dispose and remove all components rendered by the TestContextBase. By @linkdotnet.

  • Added .NET 7 as a target framework for bUnit. By @linkdotnet.

Fixed

  • Fixed step by step guide for building and viewing the documentation locally. By @linkdotnet.

  • FakeNavigationManager.NavigateTo could lead to exceptions when navigating to external url's. Reported by (@TDroogers)[https://github.com/TDroogers]. Fixed by @linkdotnet.

1.6.4

22 Feb 16:12
e10188c
Compare
Choose a tag to compare

A quick minor release that primiarily fixes a regression in 1.5.12.

Fixed

  • ClickAsync could lead to bubbling exceptions from GetDispatchEventTasks even though they should be handled. Reported by @aguacongas. Fixed by @linkdotnet.
  • Added more non bubbling events to bUnit so it behaves closer to the HTML specification. @linkdotnet.

1.5.12

15 Feb 10:51
01b7081
Compare
Choose a tag to compare

This first release of 2022 includes one fix and four additions. A huge thank you to Steven Giesel (@linkdotnet) and Denis Ekart (@denisekart) for their contributions to this release.

Also a big shout out to bUnit's sponsors who helped make this release happen.

The higher tier sponsors are:

Other sponsors are:

Added

  • Added FakeSignOutSessionStateManage type in Blazor, that makes it easy to test components that use the SignOutSessionStateManage type. By @linkdotnet.
  • Added a validation to AddChildContent method in ComponentParameterCollectionBuilder that will throw an exception if the component's ChildContent is a generic type. By @denisekart.
  • Added more optional arguments for Click and DoubleClick extensions which were introduced in .NET 5 and .NET 6. By @linkdotnet.
  • Added template support for Nunit and MSTest unit test frameworks. By @denisekart.

Fixed

  • Changed GetDispatchEventTasks for bubbling events such that handled exceptions are not rethrown later from the WaitFor... helpers methods. Reported by @AndrewStrickland. Fixed by @linkdotnet

1.4.15

18 Dec 14:47
2c1a1c1
Compare
Choose a tag to compare

This release reintroduces Stub<TComponent> and related back into the main library, so the "preview" library bunit.web.mock is already obsolete.

Big shout out to bUnit's sponsors who helped make this release happen.

The higher tier sponsors are:

Other sponsors are:

Added

  • Add ComponentFactories extensions method that makes it easy to register an instance of a replacement component. By @egil.
  • Add ability to pass ServiceProviderOptions to TestServiceProvider through property to allow users to customize the service provider. By @rodolfograve.

Fixed

  • Changed SetParametersAndRender such that it rethrows any exceptions thrown by the component under tests SetParametersAsync method. Thanks to @bonsall for reporting the issue. Fixed by @egil.
  • onclick on a button inside a form will raise the onsubmit event for the form itself. Reported by [@egil]. Fixed by @linkdotnet.
  • Only forms are allowed to have a onsubmit event handler. When onsubmit is invoked from a non-form element results in an exception. Fixed by @linkdotnet.

1.3.42

09 Nov 14:36
de625c0
Compare
Choose a tag to compare

This release includes support for .NET 6, with support for all new features in Blazor with that release. There are also a number of additions and fixes, all listed below.

Big shout out to bUnit's sponsors who helped make this release happen.

The higher tier sponsors are:

Other sponsors are:

Added

List of added functionality in this release.

  • Added support for writing tests of components that use the <FocusOnNavigate> component included in .NET 6. This includes an assertion helper method VerifyFocusOnNavigateInvoke on bUnit's JSInterop that allow you to verify that <FocusOnNavigate> has set focus on an element during render. For example, to verify that h1 selector was used to pick an element to focus on, do:

    // <App /> component uses <FocusOnNavigate>
    var cut = RenderComponent<App>();
    
    // Verifies that <FocusOnNavigate> called it's JavaScript function
    var invocation = JSInterop.VerifyFocusOnNavigateInvoke(); 
    
    // Verify that the invocation of <FocusOnNavigate> JavaScript function included the "h1" as the selector
    Assert.Equal("h1", invocation.Arguments[0]);

    By @egil.

  • Added fake version of the PersistentComponentState type in Blazor that makes it possible to test components that use the type. By @egil.

  • Added TriggerEvent method to make it easier to trigger custom events. By @egil.

  • Added History capture in the FakeNavigationManager. By @egil.

  • Added new bUnit component mocking library, available via NuGet as bunit.web.mock. It is currently in preview and the features/APIs of it will change!

  • Added WaitForElement and WaitForElements methods. These makes it possible to wait for one or more elements to appear in the DOM before continuing a test, similar to how WaitForAssertion allows you to wait for an assertion to pass, or WaitForState allows you to wait for a predicate to pass. By @egil.

Changed

  • Added automatic conversion of values (types) passed to Change() and Input() event trigger methods. This means that e.g. a DateTime passed to Change() is automatically converted to a string format that Blazor expects. By @egil.

Fixed

  • The Click and DoubleClick extension methods now set the MouseEventArgs.Detail property to 1 and 2 respectively by default, unless the user specifies something else. This makes the methods more correctly emulate how Blazor reports single or double clicks on an element in the browser. Thanks to @David-Moreira for the help troubleshooting this issue. By @egil.

  • FocusAsync() method handler on ElementReference and <FocusOnNavigate> js handler return completed Task. By @anddrzejb.

  • Fixes handling of disposed event handlers of bubbling events. See issue #518 for details. Thanks to @David-Moreira for helping debug this issue.

  • Async event trigger methods are not public. In most circumstances you do not need to use them, but if you have a scenario where you want to check that something has not happened after an event handler was triggered, then you can use the async methods and await them to know when they are completed. See #552 for details. By @egil.

1.2.49

09 Aug 14:40
54b46a0
Compare
Choose a tag to compare

Added

List of added functionality in this release.

  • Added more extensions methods to MarkupMatchesAssertExtensions to allow asserting with MarkupMatches on IEnumerable and IElement. By @jgoday.

  • Added BunitErrorBoundaryLogger implementation of IErrorBoundaryLogger (needed for Blazor's ErrorBoundary component in .NET 6.0). By @jgoday.

  • Added ComponentFactories property to the TestContextBase type. The ComponentFactories property is a ComponentFactoryCollection type that contains IComponentFactory types. These are used by bUnits component activator, whenever a component is created during testing. If no component factories is added to the collection, the standard component activator mechanism from Blazor is used. This feature makes it possible to control what components are created normally during a test, and which should be e.g. replaced by a test dummy. More info is available in issue #388.

    Learn more about this feature on the Controlling component instantiation page.

  • Added HasComponent<TComponent>() to IRenderedFragement. Use it to check if the rendered fragment contains a component of type TComponent. Added by @egil.

  • Added AddStub and Add extension methods to ComponentFactories that makes it easy to configure bUnit to replace components in the render tree with stubs. Both methods have overloads that allow for fine grained selection of component types to "double" during testing. Added by @egil in #400.

Changed

List of changes in this release.

  • Updated AngleSharp and related libraries to 0.16.0. NOTE, the new version of AngleSharp includes nullable annotations, which might affect how your code compiles, if you have nullable checking enabled in your test project. By @egil.

  • Updated .NET 6 dependencies to preview 5. By @egil.

Fixed

List of fixes in this release.

  • Fixed JSInterop error message when trying to import an unconfigured module. By @jgoday in #425.

  • Fixed issue where a registered fall-back service provider was not made available to resolve service dependencies of components under test. Thanks to @dady8889 for the reporting the issue.

  • Fixed handling of escaped uri's in FakeNavigationManager. By @linkdotnet in #460.

  • Captured error message from event dispatcher in renderer that would previously be hidden from the user. Related to issue #399.