#Testing for a raised RuntimeError
9 messages · Page 1 of 1 (latest)
test "send a boom here", %{conn: conn} do
assert_raise RuntimeError, fn ->
raise "boom"
end
end
this above works.
So is it because it's not the current process raising but the genserver running the LiveView?
How can I test that then?
Because you want to capture raises and there is exit, not raise coming from that call
LiveView lives in separate process, so the raise in the handler will be captured at the process boundary and changed to exit
How would you catch the exit then?
I tried this and it works but I wonder if there's better
test "send a boom event to the LV", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/users")
Process.flag(:trap_exit, true)
spawn_link(fn -> render_click(view, "boom", %{}) end)
assert_receive {:EXIT, apid, {%RuntimeError{message: "boom"} = err, _stack}}
dbg({apid, err})
end
You do not really need that spawn_link there IIRC