Write many tests quickly and cleanly.
Very early stage warning, do not use seriously!
edit cargo.toml
```toml
[dev-dependencies]
sweet = # current version here
[[example]] name = "sweet" path = "test/sweet.rs" ```
create file test/sweet.rs
```rust
pub use sweet::*;
sweet! { it "works" { // use assertions assert!(true == false); // or pretty matchers expect(true).tobefalse()?; expect("some string").not().tostartwith("some")?; } } ```
cargo run --example sweet
cargo install forky_cli
rust
//mount a div in a framework of your choice, we'll use leptos here :)
mount(|cx|view!{cx,<h1>"This is a heading"</h1>});
expect_el("h1")?.to_contain_text("This is a heading")?;
forky sweet
Sweet produces a single binary for each crate. The default rust intergration test runner creates a seperate binary for each test, which ramps up compile times, see this blog for more info.
The wasm runner
cargo run --example sweet -- some_dir/my_test
-w
argument
cargo watch -q -x 'run --example sweet -- -w'
Instead of an opaque panic!
, matchers provide the runner with enough info to produce a highly descriptive failure:
rs
expect("foobar").not().to_start_with("foo")?;
/*
Expected: NOT to start with 'foo'
Received: foobar
*/
Lots of web stuff happens at weird times, so we've got helpers like poll_ok
, which will wait for 4 seconds before failing.
```rs let handle = settimeout(||{ mount(|cx|view!{cx,
pollok(||expectel("div")).await? .tocontaintext("hello world!")?; ```
[[example]]
instead of [[test]]
This makes it easier for the wasm test runner to produce cleaner output, but if you're only running native tests feel free to use [[test]]
with harness=false
.
Sweet has different priorities from wasm-bindgen-test in its current state. - Interactive - the runner will list all tests and they can be run at-will in the browser. - UI - Tests are run in a mostly isolated iframe (see TODO)