sweet

Write many tests quickly and cleanly.

Very early stage warning, do not use seriously!

Features

  1. edit cargo.toml ```toml [dev-dependencies] sweet = # current version here

    [[example]] name = "sweet" path = "test/sweet.rs" ```

  2. create file test/sweet.rs ```rust

    ![feature(imported_main)]

    pub use sweet::*;

    sweet! { it "works" { // use assertions assert!(true == false); // or pretty matchers expect(true).tobefalse()?; expect("some string").not().tostartwith("some")?; } } ```

  3. run cargo run --example sweet

Quickstart - WASM

  1. Follow native quickstart
  2. install the helper cli: cargo install forky_cli
  3. add some wasm matchers to your test 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")?;
  4. run forky sweet

wasm-runner

Features

Performance

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

Args (native)

Matchers

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 */

Async Matchers

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,

"hello world!"
}); },Duration::from_millis(100));

pollok(||expectel("div")).await? .tocontaintext("hello world!")?; ```

Informative outputs

Misc

Why use [[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.

What about wasm-bindgen-test?

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)

TODO

Reference