Skip to content

add helper to assert that a LiveView will receive a message#4242

Open
SteffenDE wants to merge 3 commits into
mainfrom
sd-assert-will-receive
Open

add helper to assert that a LiveView will receive a message#4242
SteffenDE wants to merge 3 commits into
mainfrom
sd-assert-will-receive

Conversation

@SteffenDE
Copy link
Copy Markdown
Collaborator

Uses OTP 27's trace sessions to trace messages received by the LiveView.

cc @josevalim

Since this is not really LiveView specific, maybe better-suited in ExUnit?

SteffenDE added 3 commits May 22, 2026 15:11
Uses OTP 27's trace sessions to trace messages received by the LiveView.
@josevalim
Copy link
Copy Markdown
Member

Yeah, I think it could be part of Elixir, but I am not sure I like the name "assert_will_receive". You may also want to receive multiple messages within a single trace/function. Maybe an API should be more like:

trace_messages(pid, fn ->
  do_something(...)
  assert_received {:trace, ^pid, :receive, {:msg}}
end)

We call it trace_messages if we want to allow opting into tracing send. Another option is to call it explicitly trace_receive (and we introduce trace_call and trace_send in the future). Thoughts?

@josevalim
Copy link
Copy Markdown
Member

Or perhaps trace_receive(GenServer.whereis(), fn pid -> ... end).

@josevalim
Copy link
Copy Markdown
Member

Another option is:

trace(pid, [:send, :receive, call: {m, f, a}], fn -> ... end)

But most usages would likely be:

trace(pid, [:receive], fn -> ... end)

That seems to be the one with most potential for growth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants