Context

I'm writing a Blazor WASM application that stores data client-side via Blazor.IndexedDB.

I'd like to test the service that manages this data store, and I want to test against the actual IndexedDB framework. I've struggled with it silently failing. However, this framework relies on IJSRuntime and a javascript library.

Core Question

So, how can I run tests that

  • Depend on javascript
  • Are not part of the UI and should not be exposed to public navigation

Is there any way an IJSRuntime can run in a non-browser environment?

Exploration

So far I've explored

  • Searching for test suggestions: Searching has mostly led me to ways to mock IJSRuntime, but mocking the javascript will render the tests meaningless.
    • Another recommendation was e2e test frameworks like playwright, but what I'm testing does not have any visual component. It's a service that happens to save client-side via js interop
  • Inspect libraries: I've looked at several open source Blazor libraries that interop with Javascript. None that I investigated tested that interop
  • JSRuntime Instances: I've searched for concrete implementations of JSRuntime. The closest I've found is WebAssemblyJSRuntime, which is abstract but doesn't require any implementation by derivatives. Creating a derivative and running jsruntime.InvokeAsync<int>("() => 5 + 2") errors (error below)
  • Get JSRuntimeInstance from WebAssemblyHost: Trying to create a WebAssemblyHost produces the same error as trying to call jsRuntime.InvokeAsync

Error (from JSRuntime or WebAssemblyHost)

System.TypeLoadException: 'Could not load type 'WebAssembly.JSInterop.JSCallInfo' from assembly 'Microsoft.JSInterop.WebAssembly, Version=6.0.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.'

I'm guessing the underlying issue is absence of a proper environment to run javascript.

0

There are 0 best solutions below