Soenneker.Blazor.MockJsRuntime
11.0.369
Prefix Reserved
dotnet add package Soenneker.Blazor.MockJsRuntime --version 11.0.369
NuGet\Install-Package Soenneker.Blazor.MockJsRuntime -Version 11.0.369
<PackageReference Include="Soenneker.Blazor.MockJsRuntime" Version="11.0.369" />
<PackageVersion Include="Soenneker.Blazor.MockJsRuntime" Version="11.0.369" />
<PackageReference Include="Soenneker.Blazor.MockJsRuntime" />
paket add Soenneker.Blazor.MockJsRuntime --version 11.0.369
#r "nuget: Soenneker.Blazor.MockJsRuntime, 11.0.369"
#:package Soenneker.Blazor.MockJsRuntime@11.0.369
#addin nuget:?package=Soenneker.Blazor.MockJsRuntime&version=11.0.369
#tool nuget:?package=Soenneker.Blazor.MockJsRuntime&version=11.0.369
Soenneker.Blazor.MockJsRuntime
A small, thread-safe IJSRuntime test double that returns results configured by JavaScript identifier.
It is intentionally strict and minimal: unconfigured identifiers throw, arguments are ignored, and invocations are not recorded. Use a fuller mocking library when tests need argument matching, call counts, or ordered verification.
Installation
dotnet add package Soenneker.Blazor.MockJsRuntime
Registration
using Soenneker.Blazor.MockJsRuntime.Registrars;
services.AddMockJsRuntimeAsScoped();
The registrar creates one scoped MockJsRuntime and exposes that same instance as MockJsRuntime, IMockJsRuntime, and IJSRuntime. Register it only in test service collections; it does not execute JavaScript.
Configure results
using Microsoft.JSInterop;
using Soenneker.Blazor.MockJsRuntime.Abstract;
IMockJsRuntime mock = services.GetRequiredService<IMockJsRuntime>();
IJSRuntime js = services.GetRequiredService<IJSRuntime>();
mock.SetupMockResult("settings.getTheme", "dark");
string theme = await js.InvokeAsync<string>("settings.getTheme");
The generic result type must be assignable to the TValue requested by the code under test. A mismatched type produces an InvalidCastException. null can be configured for nullable/reference results:
mock.SetupMockResult<string?>("storage.get", null);
string? value = await js.InvokeAsync<string?>("storage.get");
An identifier has one configured result; configuring it again replaces the previous value. Arguments do not affect lookup:
mock.SetupMockResult("math.sum", 10);
int result = await js.InvokeAsync<int>("math.sum", 4, 6);
Calling an identifier without a setup throws InvalidOperationException. The cancellation-token overload returns a canceled ValueTask when its token is already canceled, before looking up a result.
Module imports are ordinary identifiers. When code calls InvokeAsync<IJSObjectReference>("import", path), configure "import" with an IJSObjectReference test double whose own methods model the module calls.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Microsoft.JSInterop (>= 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.369 | 5,281 | 11/30/2026 |
| 11.0.368 | 4,721 | 11/18/2026 |
| 11.0.367 | 4,881 | 11/11/2026 |
| 11.0.366 | 963 | 11/10/2026 |
| 11.0.365 | 6,213 | 10/26/2026 |
| 4.0.364 | 819 | 10/26/2026 |
| 4.0.363 | 262 | 10/25/2026 |
| 4.0.362 | 2,971 | 10/14/2026 |
| 4.0.361 | 610 | 10/14/2026 |
| 4.0.360 | 115 | 10/14/2026 |
| 4.0.355 | 1,039 | 10/12/2026 |
| 4.0.354 | 788 | 10/12/2026 |
| 4.0.353 | 2,354 | 10/11/2026 |
| 4.0.352 | 4,800 | 9/26/2026 |
| 4.0.351 | 3,559 | 9/15/2026 |
| 4.0.350 | 3,857 | 9/12/2026 |
| 4.0.349 | 1,451 | 9/8/2026 |
| 4.0.348 | 274 | 9/8/2026 |
| 4.0.347 | 9,486 | 8/29/2026 |
| 4.0.346 | 300 | 8/29/2026 |
Update soenneker/nuget-resilient-publish action to v5 (#1010)