You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+132Lines changed: 132 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,138 @@ All notable changes to **bUnit** will be documented in this file. The project ad
4
4
5
5
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) -->
6
6
7
+
## UNRELEASED [1.0.0 preview 01]
8
+
9
+
The following section list all changes in 1.0.0 preview 01.
10
+
11
+
### Added
12
+
List of new features.
13
+
14
+
- Added support for casting `BUnitJSRuntime` to `IJSInProcessRuntime` and `IJSUnmarshalledRuntime`. By [@KristofferStrube](https://github.com/KristofferStrube) in [#279](https://github.com/egil/bUnit/pull/279)
15
+
16
+
- Added support for triggering `@ontoggle` event handlers through a dedicated `Toggle()` method. By [@egil](https://github.com/egil) in [#256](https://github.com/egil/bUnit/pull/256).
17
+
18
+
- Added out of the box support for `<Virtualize>` component. When a `<Virtualize>` component is used in a component under test, it's JavaScript interop-calls are faked by bUnits JSInterop, and it should result in all items being rendered immediately. By [@egil](https://github.com/egil) in [#240](https://github.com/egil/bUnit/issues/240).
19
+
20
+
- Added support for components that call `ElementReference.FocusAsync`. These calls are handled by the bUnits JSInterop, that also allows you to verify that `FocusAsync` has been called for a specific element. For example, if a component has rendered an `<input>` element, then the following code will verify that it has been focused using `FocusAsync`:
21
+
22
+
```csharp
23
+
varcut=RenderComponent<FocusingComponent>();
24
+
25
+
varinput=cut.Find("input");
26
+
27
+
JSInterop.VerifyFocusAsyncInvoke()
28
+
.Arguments[0] // the first argument is the ElemenetReference
29
+
.ShouldBeElementReferenceTo(input);
30
+
```
31
+
32
+
By [@egil](https://github.com/egil) in [#260](https://github.com/egil/bUnit/pull/260).
33
+
34
+
- Added `Render(RenderFragment)` and `Render<TComponent>(RenderFragment)` methods to `TestContext`, as well as various overloads to the `MarkupMatches` methods, that also takes a `RenderFragment` as the expected value.
35
+
36
+
The difference between the generic `Render` method and the non-generic one is that the generic returns an `IRenderedComponent<TComponent>`, whereas the non-generic one returns a `IRenderedFragment`.
37
+
38
+
Calling `Render<TComponent>(RenderFragent)` is equivalent to calling `Render(RenderFragment).FindComponent<TComponent>()`, e.g. it returns the first component in the render tree of type `TComponent`. This is different from the `RenderComponent<TComponent>()` method, where `TComponent`_is_ the root component of the render tree.
39
+
40
+
The main usecase for these are when writing tests inside .razor files. Here the inline syntax for declaring render fragments make these methods very useful.
41
+
42
+
For example, to tests the `<Counter>` page/component that is part of new Blazor apps, do the following (inside a `CounterTest.razor` file):
43
+
44
+
```cshtml
45
+
@code
46
+
{
47
+
[Fact]
48
+
public void Counter_Increments_When_Button_Is_Clicked()
Note: This example uses xUnit, but NUnit or MSTest works equally well.
61
+
62
+
In addition to the new `Render` methods, a empty `BuildRenderTree` method has been added to the `TestContext` type. This makes it possible to inherit from the `TestContext` type in test components, removing the need for newing up the `TestContext` in each test.
63
+
64
+
This means the test component above ends up looking like this:
65
+
66
+
```cshtml
67
+
@inherts TestContext
68
+
@code
69
+
{
70
+
[Fact]
71
+
public void Counter_Increments_When_Button_Is_Clicked()
Tip: If you have multiple test components in the same folder, you can add a `_Imports.razor` file inside it and add the `@inherits TestContext` statement in that, removing the need to add it to every test component.
83
+
84
+
By [@egil](https://github.com/egil) in [#262](https://github.com/egil/bUnit/pull/262).
85
+
86
+
- Added support for `IJSRuntime.InvokeAsync<IJSObjectReference>(...)` calls from components. There is now a new setup helper methods for configuring how invocations towards JS modules should be handled. This is done with the various `SetupModule` methods available on the `BunitJSInterop` type available through the `TestContext.JSInterop` property. For example, to set up a module for handling calls to `foo.js`, do the following:
The returned `moduleJsInterop` is a `BunitJSInterop` type, which means all the normal `Setup<TResult>` and `SetupVoid` methods can be used to configure it to handle calls to the module from a component. For example, to configure a handler for a call to `hello` in the `foo.js` module, do the following:
94
+
95
+
```c#
96
+
moduleJsInterop.SetupVoid("hello");
97
+
```
98
+
99
+
By [@egil](https://github.com/egil) in [#288](https://github.com/egil/bUnit/pull/288).
100
+
101
+
- Added support for registering services in bUnits `Services` collection that implements `IAsyncDisposable`. Suggested by [@jmaillet](https://github.com/jmaillet) in [#249](https://github.com/egil/bUnit/issues/249).
102
+
103
+
### Changed
104
+
List of changes in existing functionality.
105
+
106
+
- bUnit's mock IJSRuntime has been moved to an "always on" state by default, in strict mode, and is now available through `TestContext`'s `JSInterop` property. This makes it possible for first party Blazor components like the `<Virtualize>` component, which depend on JSInterop, to "just work" in tests.
107
+
108
+
**Compatible with previous releases:** To get the same effect as calling `Services.AddMockJSRuntime()` in beta-11, which used to add the mock IJSRuntime in "loose" mode, you now just need to change the mode of the already on JSInterop, i.e. `ctx.JSInterop.Mode = JSRuntimeMode.Loose`.
109
+
110
+
**Inspect registered handlers:** Since the new design allows registering invoke handlers in the context of the `TestContext`, you might need to get already registered handlers in your individual tests. This can be done with the `TryGetInvokeHandler()` method, that will return handler that can handle the parameters passed to it. E.g. to get a handler for a `IJSRuntime.InvokaAsync<string>("getValue")`, call `ctx.JSInterop.TryGetInvokeHandler<string>("getValue")`.
111
+
112
+
Learn more [issue #237](https://github.com/egil/bUnit/issues/237). By [@egil](https://github.com/egil) in [#247](https://github.com/egil/bUnit/pull/247).
113
+
114
+
- The `Setup<TResult>(string identifier, Func<IReadOnlyList<object?>, bool> argumentsMatcher)` and `SetupVoid(string identifier, Func<IReadOnlyList<object?>, bool> argumentsMatcher)` methods in bUnits JSInterop/MockJSRuntime has a new second parameter, an `InvocationMatcher`.
115
+
116
+
The `InvocationMatcher` type is a delegate that receives a `JSRuntimeInvoation` and returns true. The `JSRuntimeInvoation` type contains the arguments of the invocation and the identifier for the invocation. This means old code using the `Setup` and `SetupVoid` methods should be updated to use the arguments list in `JSRuntimeInvoation`, e.g., change the following call:
117
+
118
+
`ctx.JSInterop.Setup<string>("foo", args => args.Count == 2)` to this:
Changed added in relation to [#240](https://github.com/egil/bUnit/issues/240) in [#257](https://github.com/egil/bUnit/issues/257) by [@egil](https://github.com/egil).
122
+
123
+
- Changed `AddTestAuthorization` such that it works in Razor-based test contexts, i.e. on the `Fixture` and `SnapshotTest` types.
124
+
125
+
### Removed
126
+
List of now removed features.
127
+
128
+
- A few bUnit internal xUnit assert helper methods, the custom `ShouldAllBe` methods, has mistakingly been part of the bunit.xunit package. These have been removed.
129
+
130
+
### Fixed
131
+
List of any bug fixes.
132
+
133
+
- When an `Add` call to the component parameter collection builder was used to select a parameter that was inherited from a base component, the builder incorrectly reported the selected property/parameter as missing on the type. Reported by [@nickmuller](https://github.com/nickmuller) in [#250](https://github.com/egil/bUnit/issues/250).
134
+
135
+
- When an element, found in the DOM tree using the `Find()`, method was removed because of an event handler trigger on it, e.g. an `cut.Find("button").Click()` event trigger method, an `ElementNotFoundException` was thrown. Reported by [@nickmuller](https://github.com/nickmuller) in [#251](https://github.com/egil/bUnit/issues/251).
136
+
137
+
- In the built-in fake authentication system in bUnit, roles and claims were not available in components through the a cascading parameter of type `Task<AuthenticationState>`. Reported by [@AFAde](https://github.com/AFAde) in [#253](https://github.com/egil/bUnit/discussions/253) and fixed in [#291](https://github.com/egil/bUnit/pull/291) by [@egil](https://github.com/egil).
138
+
7
139
## [1.0.0-beta 11] - 2020-10-26
8
140
9
141
The following section list all changes in beta-11.
Copy file name to clipboardExpand all lines: docs/site/docs/getting-started/fixture-details.md
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,10 +31,7 @@ In the example above, the setup and test methods are declared in a `@code { }` b
31
31
32
32
You can have the methods anywhere inside the test component you want, which can be useful. For example, if you have the same setup steps for multiple tests, they can be placed in a common setup method that the tests in the same test component can share, avoiding code duplication.
33
33
34
-
The methods can also be declared in the parameter directly, e.g.: `<Fixture Setup="f => f.Services.AddMockJsRuntime()" ...>`, to save space and when they are very short.
35
-
36
-
> [!TIP]
37
-
> Learn more about mocking and `AddMockJsRuntime()` on the <xref:mocking-ijsruntime> page.
0 commit comments