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
It is common for Blazor components to use `IJSRuntime` to call JavaScript, and since bUnit does not run JavaScript, emulating `IJSRuntime` is needed for components that use it. In that regard, `IJSRuntime` is no different than other services that a component might depend on.
9
9
10
-
bUnit comes with it's own JSInterop, a tailor-made implementation of `IJSRuntime` that is _active by default_, allowing you to specify how JavaScript interop calls should be handled and what values the calls should return, and also allowing you to verify that they the calls have happened. The implementation runs in "strict mode", which means means it will throw an exception if it receives an invocation it has not been configured to handle. See more about strict vs. loose mode in the following section.
10
+
bUnit comes with it's own JSInterop, a tailor-made implementation of `IJSRuntime` that is _active by default_, allowing you to specify how JavaScript interop calls should be handled and what values the calls should return, and also allowing you to verify that they the calls have happened. The implementation runs in "strict mode", which means it will throw an exception if it receives an invocation it has not been configured to handle. See more about strict vs. loose mode in the following section.
11
11
12
12
If you prefer to use the same mocking framework for all mocking in your tests to keep things consistent, general-purpose mocking frameworks like [Moq](https://github.com/Moq), [JustMock Lite](https://github.com/telerik/JustMockLite), or [NSubstitute](https://nsubstitute.github.io/) all work nicely with bUnit and can be used to mock `IJSRuntime`. In general, registering an implementation of `IJSRuntime` with bUnit's `Services` collection replaces bUnit's implementation.
13
13
@@ -27,7 +27,7 @@ By default, the bUnit's JSInterop runs in **Strict** mode. To change the mode, d
27
27
28
28
```csharp
29
29
usingvarctx=newTestContext();
30
-
ctx.JSInterop.Mode=JSRuntimeMockMode.Loose;
30
+
ctx.JSInterop.Mode=JSRuntimeMode.Loose;
31
31
```
32
32
33
33
## Setting up invocations
@@ -58,8 +58,8 @@ var plannedInvocation = ctx.JSInterop.SetupVoid("startAnimation");
58
58
// only completes or throws, it doesn’t return a value.
59
59
// Any calls to InvokeVoidAsync(...) up till this point will
60
60
// have received an incomplete Task which the component
61
-
// is awaiting until the call to SetCompleted() below.
62
-
plannedInvocation.SetCompleted();
61
+
// is awaiting until the call to SetVoidResult() below.
62
+
plannedInvocation.SetVoidResult();
63
63
```
64
64
65
65
## Verifying invocations
@@ -99,7 +99,7 @@ By default, a module Interop inherits the `Mode` setting from the root JSInterop
0 commit comments