@@ -113,16 +113,30 @@ end)
113113TestServer .plug (MyPlug )
114114```
115115
116- WebSocket endpoint can also be set up. By default a response with ` ECHO #{inspect frame} ` will be returned .
116+ WebSocket endpoint can also be set up. By default the handler will echo what was received .
117117
118118``` elixir
119- {:ok , socket} = TestServer .websocket_init (" /ws" )
119+ test " WebSocketClient" do
120+ {:ok , socket} = TestServer .websocket_init (" /ws" )
120121
121- TestServer .websocket_handle (socket)
122- TestServer .websocket_handle (socket, to: fn _frame_ , state -> {:reply , " pong" , state})
123- TestServer .websocket_handle (socket, match: fn {_opcode , message}, _state -> messsage == " ping" )
122+ {:ok , client} = WebSocketClient .start_link (TestServer .url (" /ws" ))
124123
125- TestServer .websocket_info (socket, fn state -> {:reply , {:text , " ping" }, state} end )
124+ :ok = TestServer .websocket_handle (socket)
125+ :ok = TestServer .websocket_handle (socket, to: fn {:text , " ping" }, state -> {:reply , " pong" , state})
126+ :ok = TestServer .websocket_handle (socket, match: fn {:text , message}, _state -> message == " hi" )
127+
128+ :ok = WebSocketClient .send (client, " hello" )
129+ {:ok , " hello" } = WebSocketClient .receive (client)
130+
131+ :ok = WebSocketClient .send (client, " ping" )
132+ {:ok , " pong" } = WebSocketClient .receive (client)
133+
134+ :ok = WebSocketClient .send (" hi" )
135+ {:ok , " hi" } = WebSocketClient .receive (client)
136+
137+ :ok = TestServer .websocket_info (socket, fn state -> {:reply , {:text , " ping" }, state} end )
138+ {:ok , " ping" } = WebSocketClient .receive (client)
139+ end
126140```
127141
128142<!-- MDOC !-->
0 commit comments