Testing Phoenix Channels
At this point, we've covered unit and integration testing. Now, we'll explore how to create tests for the Phoenix Channels we created in the last chapter. This is not a type of testing per se, but it's still important to explore on its own, as it comes bundled with its own set of helpers.
As we've seen in the last chapter, connecting to a channel is a two-step procedure: we first connect to the socket (through the UserSocket
module, in our case) to establish a connection with the server; then, after having a socket connected to the server, we use it to join the channels we're interested in. Therefore, we will have two test cases in this section: one for the UserSocket
module, where we'll test that this module handles the authentication properly, and another for the UserChannel
module, where we'll test that the channel reacts as expected to the events we'll create. Let's begin with the UserSocket
tests:
$ cat apps/elixir_drip_web/test/elixir_drip_web/channels/ user_socket_test...