Beta 11
[1.0.0-beta 11] - 2020-10-26
The following section list all changes in beta-11.
Big thanks to the contributors who helped with this release!
Added
List of new features.
-
Two new overloads to the
RenderFragment()andChildContent()component parameter factory methods have been added that takes aRenderFragmentas input. By @egil in #203. -
Added a
ComponentParameterCollectiontype. TheComponentParameterCollectionis a collection of component parameters, that knows how to turn those components parameters into aRenderFragment, which will render a component and pass any parameters inside the collection to that component. That logic was spread out over multiple places in bUnit, and is now owned by theComponentParameterCollectiontype. By @egil in #203. -
Added additional placeholder services for
NavigationManager,HttpClient, andIStringLocalizer, to make it easier for users to figure out why a test is failing due to missing service registration before rendering a component. By @joro550 in #223. -
Added
Keyclass that represents a keyboard key and helps to avoid constructingKeyboardEventArgsobject manually. The key can be passed toKeyPress,KeyDown, orKeyUphelper methods to raise keyboard events. TheKeyclass provides static special keys or can be obtained from character or string. Keys can be combined with key modifiers:Key.Enter + Key.Alt.For example, this makes it easier to trigger keyboard events on an element:
var cut = ctx.RenderComponent<ComponentWithKeyboardEvents>(); var element = cut.Find("input"); element.KeyDown(Key.Enter + Key.Control); // Triggers onkeydown event with Ctrl + Enter element.KeyUp(Key.Control + Key.Shift + 'B'); // Triggers onkeyup event with Ctrl + Shift + B element.KeyPress('1'); // Triggers onkeypress event with key 1 element.KeyDown(Key.Alt + "<"); // Triggers onkeydown event with Alt + <
By @duracellko in #101.
-
Added support for registering/adding components to a test context root render tree, which components under test is rendered inside. This allows you to simplify the "arrange" step of a test when a component under test requires a certain render tree as its parent, e.g. a cascading value.
For example, to pass a cascading string value
footo all components rendered with the test context, do the following:ctx.RenderTree.Add<CascadingValue<string>>(parameters => parameters.Add(p => p.Value, "foo")); var cut = ctx.RenderComponent<ComponentReceivingFoo>();
-
Added "catch-all"
Setupmethod to bUnit's mock JS runtime, that allows you to specify only the type when setting up a planned invocation. By @nemesv in #234.
Changed
List of changes in existing functionality.
-
The
ComponentParameterBuilderhas been renamed toComponentParameterCollectionBuilder, since it now builds theComponentParameterCollectiontype, introduced in this release of bUnit. By @egil in #203. -
ComponentParameterCollectionBuildernow allows adding cascading values that is not directly used by the component type it targets. This makes it possible to add cascading values to children of the target component. By @egil in #203. -
The
Add(object)has been replaced byAddCascadingValue(object)inComponentParameterCollectionBuilder, to make it more clear that an unnamed cascading value is being passed to the target component or one of its child components. It is also possible to pass unnamed cascading values using theAdd(parameterSelector, value)method, which now correctly detect if the selected cascading value parameter is named or unnamed. By @egil in #203. -
It is now possible to call the
Add(),AddChildContent()methods onComponentParameterCollectionBuilder, and the factory methodsRenderFragment(),ChildContent(), andTemplate(), multiple times for the same parameter, if it is of typeRenderFragmentorRenderFragment<TValue>. Doing so previously would either result in an exception or just the last passedRenderFragmentto be used. Now all the providedRenderFragmentorRenderFragment<TValue>will be combined at runtime into a singleRenderFragmentorRenderFragment<TValue>.For example, this makes it easier to pass e.g. both a markup string and a component to a
ChildContentparameter:var cut = ctx.RenderComponent<Component>(parameters => parameters .AddChildContent("<h1>Below you will find a most interesting alert!</h1>") .AddChildContent<Alert>(childParams => childParams .Add(p => p.Heading, "Alert heading") .Add(p => p.Type, AlertType.Warning) .AddChildContent("<p>Hello World</p>") ) );
-
All test doubles are now in the same namespace,
Bunit.TestDoubles. So all import statements forBunit.TestDoubles.JSInteropandBunit.TestDoubles.Authorizationmust be changed toBunit.TestDoubles. By @egil in #223. -
Marked MarkupMatches methods as assertion methods to stop SonarSource analyzers complaining about missing assertions in tests. By @egil in #229.
-
AddTestAuthorizationnow extendsTestContextinstead ofTestServiceProvider, and also automatically adds theCascadingAuthenticationStatecomponent to the root render tree. @egil in #237.
Removed
List of now removed features.
- The async event dispatcher helper methods have been removed (e.g.
ClickAsync()), as they do not provide any benefit. If you have an event that triggers async operations in the component under test, instead usecut.WaitForState()orcut.WaitForAssertion()to await the expected state in the component.
Fixed
List of any bug fixes.
- Using the ComponentParameterCollectionBuilder's
Add(p => p.Param, value)method to add a unnamed cascading value didn't create an unnnamed cascading value parameter. By @egil in #203. Credits to Ben Sampica (@benjaminsampica) for reporting and helping investigate this issue. - Triggered events now bubble correctly up the DOM tree and triggers other events of the same type. This is a potentially breaking change, since this changes the behaviour of event triggering and thus you might see tests start breaking as a result hereof. By @egil in #119.