Dje*_*ent 5 unit-testing rust webassembly wasm-bindgen rust-wasm
WASM我正在使用该框架编写前端seed。
我想用单元测试来测试我的模块之一,但我无法让它们来测试WASM代码。这是我的测试套件:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_non_wasm() {
assert_eq!("test", "test");
}
#[test]
fn check_home() {
assert_eq!(Urls::new().home().to_string(), "/");
}
}
Run Code Online (Sandbox Code Playgroud)
第一个测试通过了,因为没有使用任何与WASM. 另一个测试失败并出现以下错误:
thread 'urls::tests::check_home' panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets'
Run Code Online (Sandbox Code Playgroud)
如果我运行cargo make test --chrome它甚至看不到这些测试。
我尝试运行cargo test --target wasm32-unknown-unknown,但失败并出现以下错误:
could not execute process `C:\Users\djenty\w\frontend\target\wasm32-unknown-unknown\debug\deps\w_frontend-2b6de747c6501f70.wasm` (never executed)
Run Code Online (Sandbox Code Playgroud)
rustup显示目标已安装:
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-pc-windows-msvc
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.54.0 (a178d0322 2021-07-26)
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?