plushie/testing/widget_harness
Widget test harness for custom widgets.
Wraps a widget in a minimal host app for isolated testing. The harness records semantic events emitted by the widget (filtering out canvas framework noise) and exposes helpers for querying the widget’s emitted output.
Usage
import plushie/testing
import plushie/testing/widget_harness
pub fn clicking_star_emits_select_test() {
let app = widget_harness.harness("stars", star_rating_def(), StarProps(rating: 3, max: 5))
let ctx = testing.start(app)
let ctx = testing.canvas_press(ctx, "stars", 50.0, 10.0)
let events = widget_harness.events(testing.model(ctx))
// assert on events...
testing.stop(ctx)
}
The harness model tracks all emitted events. Use last_event and
events to inspect what the widget produced.
Types
Model for the widget test harness. Tracks emitted events.
pub type HarnessModel {
HarnessModel(events: List(event.Event))
}
Constructors
-
HarnessModel(events: List(event.Event))Arguments
- events
-
All events received by the harness (newest first).
Values
pub fn events(model: HarnessModel) -> List(event.Event)
Get all events captured by the harness (newest first).
pub fn harness(
widget_id: String,
def: widget.WidgetDef(state, props),
props: props,
) -> app.App(HarnessModel, event.Event)
Build a test harness app that hosts a widget.
The harness wraps the widget in a minimal window layout and records
all non-framework events. Canvas lifecycle events (focus, blur,
element enter/leave) are filtered out as noise; only semantic
events emitted by the widget’s handle_event are captured.
pub fn has_event(
model: HarnessModel,
predicate: fn(event.Event) -> Bool,
) -> Bool
Check if any captured event matches the predicate.
pub fn last_event(
model: HarnessModel,
) -> Result(event.Event, Nil)
Get the most recent event captured by the harness.