wasm-bindgen
wasm-bindgen copied to clipboard
docs(wasm-bindgen-test): testing using private module still works?
Summary
From the docs:
One other difference is that the tests must be in the root of the crate, or within a
pub mod. Putting them inside a private module will not work.
But seem this code is just works now:
use web_sys::js_sys::Math;
fn rand() -> usize {
Math::floor(Math::random() * 10.0) as usize
}
#[cfg(test)]
mod tests {
use wasm_bindgen_test::wasm_bindgen_test;
use web_sys::console;
use wasm_bindgen_test::console_log;
#[wasm_bindgen_test]
fn it_works() {
console::info_1(&"THIS IS WORKS".into());
console_log!("This is works too");
let rand = super::rand();
assert!(rand < 0)
}
}
- Run with:
wasm-pack test --node
Output:
failures:
---- wasm_test_bug::tests::it_works output ----
log output:
This is works too
info output:
THIS IS WORKS
error output:
panicked at src/lib.rs:20:9:
assertion failed: rand < 0
Additional Details
- Node version
v20.13.1
- wasm-bindgen version
wasm-bindgen 0.2.92
- wasm-pack version
wasm-pack 0.12.1
I'm not aware of the historic context here, but this has been working as long as I have known wasm-bindgen.
You can continue relying on it as it won't stop working unless Rust itself changes something.
The documentation has to be updated though, so I will leave this issue open for that.