Open Source Docs

Spoonbill

Server-side SPA framework for Scala 3

Testing

Renderer-level testing with spoonbill-testkit


Testing With spoonbill-testkit

Spoonbill includes a renderer-level testkit (modules/testkit) for testing UI behavior without running a real browser session.

Key pieces:

  • PseudoHtml.render(dom) renders an Avocet node to pseudo DOM and keeps:

    • DOM id to ElementId mapping

    • event handlers

  • Browser.event(...) simulates event propagation and returns captured actions (Publish, Transition, PropertySet, and so on).

Selector helpers

PseudoHtml provides:

  • byAttrEquals(name, value) for exact attribute matching

  • firstByTag(tagName) for first-match tag lookup

val pd = PseudoHtml.render(dom).pseudoDom

val submitButtonId = pd.byAttrEquals("name", "submit").headOption.map(_.id)
val firstDivId = pd.firstByTag("div").map(_.id)

Targeting by ElementId

When a renderer uses explicit elementId(...), tests can target that Spoonbill id directly:

val clickTarget = elementId(Some("click-target"))

val actionsF =
  Browser().eventByElementId(
    state = initialState,
    dom = dom,
    event = "click",
    targetElementId = clickTarget
  )

Advanced targeting with element map

For full control, use the overload that exposes the Avocet-to-ElementId map:

Browser().event(
  state = initialState,
  dom = dom,
  event = "click",
  target = (_, elementMap) =>
    elementMap.collectFirst { case (domId, eid) if eid == clickTarget => domId },
  eventData = ""
)

Run tests

nix develop --command sbt test