Shogun.Websocket.GunTest (shogun v0.1.3)
GunTest can help to test your implementation of Shogun.Websocket Follow the steps to test it out
First step:
set the client for the websocket in config/test.exs
config :shogun, Shogun.Websocket,
client: Shogun.Websocket.GunTest
Second step:
now on your test, you can control the messages that your websocket received.
defmodule MyApp.WebsocketTest do
use ExUnit.Case, async: true
alias Shogun.Websocket.GunTest
setup _context do
{:ok, ws_pid} = start_supervised({MyApp.Websocket, url: "test"})
[ws_pid: ws_pid]
end
test "validate message test is received by the client", %{ws_pid: ws_pid} do
GunTest.receive_message(ws_pid, "test")
assert :sys.get_state(ws_pid).internal_state.message == "test"
end
end
Link to this section Summary
Link to this section Functions
Link to this function