Unable to use `yew::tests` because it is `#cfg(test)`
Problem
I am unable to use the yew::tests module in my tests. Sorry if I'm being stupid, but I think it's because the cfg(test) does not get passed on to crates you depend on.
Steps To Reproduce Steps to reproduce the behavior:
$ cargo new yew-app
Created binary (application) `yew-app` package
$ cd yew-app/
$ vim src/main.rs Cargo.toml
$ cat Cargo.toml
[package]
name = "yew-app"
version = "0.1.0"
edition = "2021"
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
$ cat src/main.rs
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod test {
use yew::tests::layout_tests;
#[test]
fn my_test() {
// Do something with layout_tests
}
}
$ cargo test
...
error[E0432]: unresolved import `yew::tests`
--> src/main.rs:7:14
|
7 | use yew::tests::layout_tests;
| ^^^^^ could not find `tests` in `yew`
Expected behavior
Because of the information here: https://yew.rs/docs/more/testing I expected to be able to use this module.
Environment:
- Yew version: v0.20.0
- Rust version: 1.70.0
- Build tool, if relevant: cargo
- OS, if relevant: Linux
Questionnaire
- [x] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [ ] I don't have time to fix this right now, but maybe later
I'm having problems with this too and haven't had the time to figure out what magic cargo settings I need to get this to work.
Wouldn't it make sense to just expose regardless of if you're testing or not? The compiler should just remove this dead code from the executable on build anyway (if you don't import it certainly won't be included).