Dstar.Test (dstar v0.1.0)

Copy Markdown View Source

Assertions for Dstar SSE responses in Plug.Test / Phoenix.ConnTest tests. Chunked SSE bodies accumulate in conn.resp_body on the test adapter; these helpers parse them back into events.

conn = post(conn, "/counter/_event/increment")
assert_patched_signals(conn, %{count: 1})
assert_patched_element(conn, "#history")

Summary

Functions

Asserts a datastar-patch-elements event targets target — either via an explicit selector line or via an id attribute in the patched HTML (pass the target as "#the-id" in both cases). Returns the conn for piping.

Asserts the given signals (a subset) were patched. Keys may be atoms or strings; values compare against the JSON-decoded patch. Returns the conn for piping.

Returns the merged map of all signals patched on the conn.

Parses the SSE events from a conn (or raw body string) into a list of %{type: String.t() | nil, data: [String.t()]}. This parser understands Dstar's own SSE output format ("event: " / "data: " with a trailing space, LF line endings) — it is not a general-purpose SSE parser.

Functions

assert_patched_element(conn, target)

Asserts a datastar-patch-elements event targets target — either via an explicit selector line or via an id attribute in the patched HTML (pass the target as "#the-id" in both cases). Returns the conn for piping.

assert_patched_signals(conn, expected)

Asserts the given signals (a subset) were patched. Keys may be atoms or strings; values compare against the JSON-decoded patch. Returns the conn for piping.

patched_signals(conn)

Returns the merged map of all signals patched on the conn.

sse_events(conn)

Parses the SSE events from a conn (or raw body string) into a list of %{type: String.t() | nil, data: [String.t()]}. This parser understands Dstar's own SSE output format ("event: " / "data: " with a trailing space, LF line endings) — it is not a general-purpose SSE parser.