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 ComponentJSInteropProperties
| Name | Description |
|---|---|
| Invocations | Gets the calls, in the order they were made. |
| Mode | Gets or sets what a call that is not set up returns when the page does not run JavaScript. |
Invocations
ComponentJSInterop.csGets the calls, in the order they were made.
public IReadOnlyList<JSInvocation> Invocations { get; }Property value
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
Methods
| Name | Description |
|---|---|
| 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.csGets the calls of a JavaScript function.
public IReadOnlyList<JSInvocation> GetInvocations(string identifier)Parameters
identifierstring- The identifier of the function.
Returns
IReadOnlyList<JSInvocation> The calls, in the order they were made.
Setup overloads
Setup(string, Func<JSInvocation, object?>)
ComponentJSInterop.csSets the result of the calls of a JavaScript function.
public void Setup(string identifier, Func<JSInvocation, object?> handler)Parameters
identifierstring- The identifier of the function (
"localStorage.getItem"). handlerFunc<JSInvocation, object?>- Returns the result of a call. The result is converted to the type the component expects.
Setup(string, object?)
ComponentJSInterop.csSetupVoid(string, Action<JSInvocation>?)
ComponentJSInterop.csAccepts the calls of a JavaScript function that returns nothing.
public void SetupVoid(string identifier, Action<JSInvocation>? handler = null)Parameters
identifierstring- The identifier of the function.
handlerAction<JSInvocation>?- Invoked for each call, or null.