Testing Brew components
Brew.test mounts a component and performs real snapshot round-trips through the update pipeline (JSON encode, checksum, hydrate, actions, render). No browser required.
Register providers the same way as production (at least Brew + Crema when you assert HTML from views). In tests, call Brew.reset() / Kona.reset() between cases if you boot a full application.
@Testfun increments() { Brew.test(Counter::class.java, mapOf("start" to 2)) .assertSet("count", 2) .call("increment") .assertSet("count", 3) .assertSee(3)}@Testvoid increments() { Brew.test(Counter.class, Map.of("start", 2)) .assertSet("count", 2) .call("increment") .assertSet("count", 3) .assertSee(3);}You can also address by name: Brew.test("counter", mapOf("start" to 2)).
Interactions
Section titled “Interactions”| Method | Role |
|---|---|
set(name, value) / set(map) |
Property updates |
toggle(name) |
Flip boolean |
call(method, *params) |
Invoke action |
refresh() |
$refresh |
commit() |
$commit |
Assertions
Section titled “Assertions”| Assertion | Checks |
|---|---|
assertSet / assertNotSet |
Property equals (loose by default; strict = true for ==) |
assertCount |
Collection / map / array / CharSequence size |
assertSee / assertDontSee |
Visible text (HTML-escaped by default) |
assertSeeHtml / assertDontSeeHtml |
Raw HTML substring |
assertSeeInOrder |
Multiple needles in order |
assertViewHas / assertViewIs |
View data / view name |
assertRenderSkipped / assertRenderNotSkipped |
skipRender / @Renderless |
assertStatus |
Last HTTP status from the round-trip |
assertForbidden / assertUnauthorized |
403 / 401 |
Accessors
Section titled “Accessors”val t = Brew.test("counter")t.instance() // live Componentt.id()t.html() // last HTML (optional strip of wire:snapshot/effects)t.get("todos.0.title")t.snapshot()t.effects()t.viewData("title")Scaffold
Section titled “Scaffold”./grind make:brew counter --testHTTP smoke tests
Section titled “HTTP smoke tests”Samples also exercise the real endpoint: GET / for embedded HTML, then POST /brew/update with X-Brew, CSRF cookie, and a snapshot taken from wire:snapshot. Prefer Brew.test for component logic; use HTTP tests for middleware, CSRF, and asset injection.
- Components — what you are testing
- Actions —
calltargets - Lifecycle — hooks that run inside each round-trip