Skip to content
Brew

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.

@Test
fun increments() {
Brew.test(Counter::class.java, mapOf("start" to 2))
.assertSet("count", 2)
.call("increment")
.assertSet("count", 3)
.assertSee(3)
}

You can also address by name: Brew.test("counter", mapOf("start" to 2)).

Method Role
set(name, value) / set(map) Property updates
toggle(name) Flip boolean
call(method, *params) Invoke action
refresh() $refresh
commit() $commit
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
val t = Brew.test("counter")
t.instance() // live Component
t.id()
t.html() // last HTML (optional strip of wire:snapshot/effects)
t.get("todos.0.title")
t.snapshot()
t.effects()
t.viewData("title")
Terminal window
./grind make:brew counter --test

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.