PhoenixHtmxWs.SocketTest (phoenix_htmx_ws v0.1.0)

Copy Markdown View Source

Test helpers that exercise the same transport callbacks as a real connection.

The returned socket value is opaque transport state. frames always contains {:text, binary} tuples, matching the WebSocket wire contract.

Summary

Functions

Connects and mounts a socket module through its real callbacks.

Sends one raw binary frame.

Sends an event using the htmx 4 JSON frame shape.

Sends one raw text frame, including malformed JSON.

Delivers a process message through the real transport callback.

Returns the public socket state for assertions.

Terminates the transport state through the real callback.

Types

t()

@opaque t()

Functions

connect(module, opts \\ [])

@spec connect(
  module(),
  keyword()
) :: {:ok, t()} | {:stop, term(), t()} | :error | {:error, term()}

Connects and mounts a socket module through its real callbacks.

send_binary(socket_test, payload)

@spec send_binary(t(), binary()) :: {:ok, [{:text, binary()}], t()} | tuple()

Sends one raw binary frame.

send_event(socket, event, params \\ %{})

@spec send_event(t(), binary(), map()) :: {:ok, [{:text, binary()}], t()} | tuple()

Sends an event using the htmx 4 JSON frame shape.

send_frame(socket_test, payload)

@spec send_frame(t(), binary()) :: {:ok, [{:text, binary()}], t()} | tuple()

Sends one raw text frame, including malformed JSON.

send_info(socket_test, message)

@spec send_info(t(), term()) :: {:ok, [{:text, binary()}], t()} | tuple()

Delivers a process message through the real transport callback.

socket(socket_test)

@spec socket(t()) :: PhoenixHtmxWs.Socket.t()

Returns the public socket state for assertions.

terminate(socket_test, reason)

@spec terminate(t(), term()) :: :ok

Terminates the transport state through the real callback.