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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Blazor.MockJsRuntime" Version="11.0.369" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.MockJsRuntime" Version="11.0.369" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.MockJsRuntime" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Blazor.MockJsRuntime --version 11.0.369
                    
#r "nuget: Soenneker.Blazor.MockJsRuntime, 11.0.369"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Blazor.MockJsRuntime@11.0.369
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Blazor.MockJsRuntime&version=11.0.369
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.MockJsRuntime&version=11.0.369
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Update soenneker/nuget-resilient-publish action to v5 (#1010)