Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Simular IJSRuntime InvokeVoidAsync

Quiero InvokeVoidAsync de C# Blazor IJSRuntime usando xunit y Moq . Hasta ahora tengo una función simple para probar que las llamadas await _js.InvokeVoidAsync("register") , donde _js es un objeto de tipo IJSRuntime .

Mi prueba se parece a la siguiente:

 [Fact] public async Task Register_Test() { var jsMock = new Mock<IJSRuntime>(); jsMock.Setup(x => x.InvokeAsync<object>(It.IsAny<string>(), It.IsAny<object[]>())).Returns(new ValueTask<object>()); ... jsMock.Verify(x => x.InvokeAsync<bool>("register"), Times.Once()); }

Tenga en cuenta que no llamo a InvokeVoidAsync directamente como se indica aquí y estoy tratando de aplicar la solución desde aquí que describe cómo usar InvokeAsync<type> .

Esta prueba se compila, pero mientras se ejecuta aparece un error que dice

 System.InvalidCastException : Unable to cast object of type 'System.Threading.Tasks.ValueTask`1[System.Object]' to type 'System.Threading.Tasks.ValueTask`1[Microsoft.JSInterop.Infrastructure.IJSVoidResult]'.

¿Cómo puedo llamar y probar InvokeVoidAsync desde IJSRuntime ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El mensaje de error fue bastante útil.

La prueba correcta se vería así:

 { var jsMock = new Mock<IJSRuntime>(); jsMock.Setup(x => x.InvokeAsync<Microsoft.JSInterop.Infrastructure.IJSVoidResult>(It.IsAny<string>(), It.IsAny<object[]>())).Returns(new ValueTask<Microsoft.JSInterop.Infrastructure.IJSVoidResult>()); ... jsMock.Verify(x => x.InvokeAsync<Microsoft.JSInterop.Infrastructure.IJSVoidResult>("register"), Times.Once()); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!