jlazor:针对IJSruntime和JavaScript框架进行测试,没有被嘲笑,也没有UI。或者如何在浏览器外运行JS
上下文
我正在编写一个通过 blazor.indexeddb 来存储数据客户端的Blazor WASM应用程序。
我想测试管理此数据存储的服务,我想根据实际的索引框架进行测试。我为此而苦苦挣扎。但是,此框架依赖于ijsruntime
和一个JavaScript库。
核心问题
因此,如何运行
- 依赖于JavaScript的
- 测试不是UI的一部分,不应接触公共导航,
如果有任何办法可以在非浏览器环境中进行IJSruntime?
到目前为止,我已经探索了
- 搜索测试建议:搜索主要导致我采用模拟
ijsruntime
的方法,但是模拟JavaScript将使测试变得毫无意义。- 另一个建议是E2E测试框架,例如 playwright 成分。这是一项通过JS Interop 来保存客户端的服务
- :我已经查看了几个与JavaScript互动的开源外汇库。我没有研究过测试的Interop
- jsruntime实例:我已经搜索了JSruntime的具体实现。我发现的最接近的是 WebAssemblyjsruntime ,这是抽象的,但不需要衍生工具实现。创建一个导数和运行
jsruntime.invokeasync< int>(“()=> 5 + 2”)
errors> errors> errors(以下错误 - ) WebAssemblyHost产生的错误与尝试调用
jsruntime.invokeasync
error(来自jsruntime或WebAssemblyHost)
system.typeloadexception:“无法加载type type'webAssembly.jsinterop.jsinterop.jscallinfo'来自汇编'Microsoft.jsinterop.webassembly,版本= 6.0.4.0,culture = Neutral,public Keytry,publicKeyToken = adb9793829dddae60' 4不正确对齐或与非对象字段重叠。'
我猜潜在的问题是没有适当的环境来运行JavaScript。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论