Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(wasm-bindgen-test): testing using private module still works? #3975

Open
afifurrohman-id opened this issue May 30, 2024 · 1 comment
Open
Labels
docs Issues related to documentation

Comments

@afifurrohman-id
Copy link

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
@daxpedda
Copy link
Collaborator

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.

@daxpedda daxpedda added docs Issues related to documentation and removed question labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Issues related to documentation
Projects
None yet
Development

No branches or pull requests

2 participants