ComponentJSInterop Class

Configures the JavaScript interop of the components (IJSRuntime): the results of the calls, and the calls that were made. A call that is not set up calls the JavaScript functions of the page when ComponentTestHostOptions.EnableJavaScript is true, and otherwise follows ComponentJSInterop.Mode.

public sealed class ComponentJSInterop

Properties

NameDescription
InvocationsGets the calls, in the order they were made.
ModeGets or sets what a call that is not set up returns when the page does not run JavaScript.

Gets the calls, in the order they were made.

public IReadOnlyList<JSInvocation> Invocations { get; }

Gets or sets what a call that is not set up returns when the page does not run JavaScript.

public JSInteropMode Mode { get; set; }

Property value

JSInteropMode

Methods

NameDescription
GetInvocations(string)Gets the calls of a JavaScript function.
Setup(string, Func<JSInvocation, object?>)Sets the result of the calls of a JavaScript function.
Setup(string, object?)Sets the result of the calls of a JavaScript function.
SetupVoid(string, Action<JSInvocation>?)Accepts the calls of a JavaScript function that returns nothing.

GetInvocations(string)

ComponentJSInterop.cs

Gets the calls of a JavaScript function.

public IReadOnlyList<JSInvocation> GetInvocations(string identifier)

Parameters

identifier string
The identifier of the function.

Returns

IReadOnlyList<JSInvocation> The calls, in the order they were made.

Setup overloads

Setup(string, Func<JSInvocation, object?>)

ComponentJSInterop.cs

Sets the result of the calls of a JavaScript function.

public void Setup(string identifier, Func<JSInvocation, object?> handler)
Parameters
identifier string
The identifier of the function ("localStorage.getItem").
handler Func<JSInvocation, object?>
Returns the result of a call. The result is converted to the type the component expects.

Setup(string, object?)

ComponentJSInterop.cs

Sets the result of the calls of a JavaScript function.

public void Setup(string identifier, object? result)
Parameters
identifier string
The identifier of the function.
result object?
The result of the calls.

SetupVoid(string, Action<JSInvocation>?)

ComponentJSInterop.cs

Accepts the calls of a JavaScript function that returns nothing.

public void SetupVoid(string identifier, Action<JSInvocation>? handler = null)

Parameters

identifier string
The identifier of the function.
handler Action<JSInvocation>?
Invoked for each call, or null.