Skip to content

Allow untyped JSInterop.Setup methods, that matches with any type #361

@egil

Description

@egil

A generic Setup(InvocationMatcher) method is needed, that does not specify the return type at compile time is needed, to make it easy for folks to set up a "catch all of my calls" in a single Setup method call.

The suggested solution

Add a new non-generic Setup method that takes a InvocationMatcher as input, and returns new type of handler, with the following signature:

public JSRuntimeInvocationHandler SetResult<TReturnType>(Func<JSRuntimeInvocation, TReturnType> resultFactory);
public JSRuntimeInvocationHandler SetCanceled<TReturnType>();
public JSRuntimeInvocationHandler SetException<TResultType, TException>(Func<JSRuntimeInvocation, TException> exceptionFactory) where TException : Exception

This JSRuntimeInvocationHandler could serve as a base class for all other handler types, as it is very generic and can be used in all cases.

The Set* methods allow the user to set results based on the return type of the InvokeAsync call.

Additional context

This feature is especially useful for component vendors that want to have a single Setup and SetResult call in their helper libraries for bUnit. This will allow them to easily ignore all calls made to their JavaScript code. Currently, they have to add one Setup<T>(...).SetResult(..) call per type their JavaScript library returns. With this addition, they will be able to create a more generic solution that uses factory methods to do most of the work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions