Skip to content

Commit 9198b4e

Browse files
committed
Update LiveQueryClient-test.js
1 parent 31dac3b commit 9198b4e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/__tests__/LiveQueryClient-test.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ describe('LiveQueryClient', () => {
307307
expect(liveQueryClient.subscriptions.size).toBe(1);
308308
});
309309

310-
it('can handle WebSocket error response message', () => {
310+
it('can handle WebSocket error response message', async () => {
311311
const liveQueryClient = new LiveQueryClient({
312312
applicationId: 'applicationId',
313313
serverURL: 'ws://test',
@@ -329,13 +329,17 @@ describe('LiveQueryClient', () => {
329329
isChecked = true;
330330
expect(error).toEqual('error');
331331
});
332-
333-
liveQueryClient._handleWebSocketMessage(event);
332+
try {
333+
liveQueryClient._handleWebSocketMessage(event);
334+
await liveQueryClient.connectPromise;
335+
} catch (error) {
336+
expect(error.message).toEqual('error');
337+
}
334338

335339
expect(isChecked).toBe(true);
336340
});
337341

338-
it('can handle WebSocket error while subscribing', () => {
342+
it('can handle WebSocket error while subscribing', async () => {
339343
const liveQueryClient = new LiveQueryClient({
340344
applicationId: 'applicationId',
341345
serverURL: 'ws://test',
@@ -363,7 +367,12 @@ describe('LiveQueryClient', () => {
363367
expect(error).toEqual('error thrown');
364368
});
365369

366-
liveQueryClient._handleWebSocketMessage(event);
370+
try {
371+
liveQueryClient._handleWebSocketMessage(event);
372+
await Promise.all([subscription.connectPromise, subscription.subscribePromise, liveQueryClient.connectPromise, liveQueryClient.subscribePromise]);
373+
} catch (e) {
374+
expect(e.message).toEqual('error thrown');
375+
}
367376

368377
jest.runOnlyPendingTimers();
369378
expect(isChecked).toBe(true);
@@ -740,7 +749,7 @@ describe('LiveQueryClient', () => {
740749
liveQueryClient._handleWebSocketError(error);
741750
});
742751

743-
it('can handle WebSocket reconnect on error event', () => {
752+
it('can handle WebSocket reconnect on error event', async () => {
744753
const liveQueryClient = new LiveQueryClient({
745754
applicationId: 'applicationId',
746755
serverURL: 'ws://test',
@@ -764,7 +773,12 @@ describe('LiveQueryClient', () => {
764773
expect(error).toEqual(data.error);
765774
});
766775
const spy = jest.spyOn(liveQueryClient, '_handleReconnect');
767-
liveQueryClient._handleWebSocketMessage(event);
776+
try {
777+
liveQueryClient._handleWebSocketMessage(event);
778+
await liveQueryClient.connectPromise;
779+
} catch (e) {
780+
expect(e.message).toBe('Additional properties not allowed');
781+
}
768782

769783
expect(isChecked).toBe(true);
770784
expect(liveQueryClient._handleReconnect).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)