How to test subscription of channel

‘Subscribing to external topics’ is really interesting concept.

But I can’t find the way to test the subscription of channel. How to do that?

What exactly are you trying to test? That a message was sent? That a message was received? Something else?

That socket is really subscribing a channel.

For example,

def join("test", %{"id" => id}, socket) do
  :ok = TestWeb.Endpoint.subscribe("id:#{id}")
  {:ok, socket}

I want to know I didn’t forget subscribing “id:#{id}” on test.

Hmmm, usually I would assert that a message that is sent to the "id:#{id}" topic is received by the test process. Perhaps you could create a helper that will assert that the a test-specific message is received.

1 Like