In my Blazor app, I am trying to test delete code, when the button is clicked, it will run the following code to display a confirmation dialog:
public async Task DeleteDocument(DocumentViewModel document)
{
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure?");
if (confirmed)
{
... do some delete code here
}
In my test project I have this line:
_mockJsRuntime
.Setup(js => js.InvokeAsync<bool>(It.IsAny<string>(), It.IsAny<object>()))
.Returns(ValueTask.FromResult(true));
When I run the test, I get the following error:
Extension methods (here: JSRuntimeExtensions.InvokeAsync) may not be used in setup / verification expressions.
What can I do to to be able to test my DeleteDocument method?