Hi, I’m trying to write a test for a channel and am confused by the way the test is failing.
My test:
defmodule MusicJamServerWeb.RoomChannelTest do
use MusicJamServerWeb.ChannelCase
setup do
{:ok, _, socket} =
UserSocket
|> socket("user_id", %{some: :assign})
|> subscribe_and_join(MusicJamServerWeb.RoomChannel, "room:lobby")
%{socket: socket}
end
test "broadcasts instrument updates to room:{id}", %{socket: socket} do
push(socket, "update_instrument", %{"body" => "muzak"})
assert_broadcast "update_instrument", %{"body" => "muzak"}
end
end
My ChannelCase module, where I reference the endpoint:
defmodule MusicJamServerWeb.ChannelCase do
use ExUnit.CaseTemplate
using do
quote do
# Import conveniences for testing with channels
import Phoenix.ChannelTest
# The default endpoint for testing
@endpoint MusicJamServerWeb.Endpoint
end
end
setup _tags do
# pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Demo.Repo, shared: not tags[:async])
# on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
:ok
end
end
And in my Endpoint module, I declare a socket mount like so:
defmodule MusicJamServerWeb.Endpoint do
...
socket "/socket", MusicJamServerWeb.UserSocket,
websocket: true,
longpoll: false
...
end
Yet the test fails because it thinks Endpoint does not contain a socket mount?
1) test broadcasts instrument updates to room:{id} (MusicJamServerWeb.RoomChannelTest)
test/music_jam_server_web/channels/room_channel_test.exs:14
** (ArgumentError) no socket supervision tree found for UserSocket.
Ensure your MusicJamServerWeb.Endpoint contains a socket mount, for example:
socket "/socket", UserSocket,
websocket: true,
longpoll: true