shelly-test 0.4.0

Testing helpers and macros for Shelly LiveView apps.
Documentation

shelly-test

Testing helpers and macros for Shelly LiveView applications.

This crate provides concise test ergonomics for session mounting, event dispatching, and server message assertions.

Install

cargo add --dev shelly-test

Quick Example

use shelly::{Html, LiveView};
use shelly_test::{assert_patch, dispatch, event, mount_session};

#[derive(Default)]
struct Counter {
    count: i64,
}

impl LiveView for Counter {
    fn handle_event(
        &mut self,
        event: shelly::Event,
        _ctx: &mut shelly::Context,
    ) -> shelly::LiveResult {
        if event.name == "inc" {
            self.count += 1;
        }
        Ok(())
    }

    fn render(&self) -> Html {
        Html::new(format!("<h1>{}</h1>", self.count))
    }
}

let mut session = mount_session!(Counter);
let messages = dispatch!(session, event!("inc"));
assert_patch!(messages, target = "root", revision = 1);

API Docs

https://docs.rs/shelly-test