Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 9312d63

Browse files
authored
Merge pull request #92 from hubert-deriv/useWS_test_cov
Hubert / useWS test coverage
2 parents 606467b + 5ae6987 commit 9312d63

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/hooks/useWs/__tests__/useWs.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,39 @@ describe('Use WS', () => {
205205
req_id: 1,
206206
});
207207
});
208+
209+
it('Should be able to clear the websocket call', async () => {
210+
const { result, waitForNextUpdate } = renderHook(() => useWS('ping'));
211+
212+
expect(result.current.is_loading).toBeFalsy();
213+
214+
act(() => {
215+
result.current.send();
216+
});
217+
expect(result.current.is_loading).toBeTruthy();
218+
219+
await expect(wsServer).toReceiveMessage({ ping: 1, req_id: 1 });
220+
221+
wsServer.send({
222+
echo_req: {
223+
ping: 1,
224+
req_id: 1,
225+
},
226+
msg_type: 'ping',
227+
ping: 'pong',
228+
req_id: 1,
229+
});
230+
231+
await waitForNextUpdate();
232+
233+
expect(result.current.is_loading).toBeFalsy();
234+
235+
expect(result.current.data).toBe('pong');
236+
237+
act(() => {
238+
result.current.clear();
239+
});
240+
241+
expect(result.current.data).toBe(null);
242+
});
208243
});

0 commit comments

Comments
 (0)