@@ -756,6 +756,21 @@ describe('LiveQueryClient', () => {
756
756
spy . mockRestore ( ) ;
757
757
} ) ;
758
758
759
+ it ( 'can handle WebSocket disconnect if already disconnected' , async ( ) => {
760
+ const liveQueryClient = new LiveQueryClient ( {
761
+ applicationId : 'applicationId' ,
762
+ serverURL : 'ws://test' ,
763
+ javascriptKey : 'javascriptKey' ,
764
+ masterKey : 'masterKey' ,
765
+ sessionToken : 'sessionToken' ,
766
+ } ) ;
767
+ const spy = jest . spyOn ( liveQueryClient , '_handleReconnect' ) ;
768
+ liveQueryClient . state = 'disconnected' ;
769
+ liveQueryClient . _handleWebSocketClose ( ) ;
770
+ expect ( liveQueryClient . _handleReconnect ) . toHaveBeenCalledTimes ( 0 ) ;
771
+ spy . mockRestore ( ) ;
772
+ } ) ;
773
+
759
774
it ( 'can subscribe' , async ( ) => {
760
775
const liveQueryClient = new LiveQueryClient ( {
761
776
applicationId : 'applicationId' ,
@@ -886,6 +901,31 @@ describe('LiveQueryClient', () => {
886
901
expect ( liveQueryClient . socket . send ) . toHaveBeenCalledTimes ( 0 ) ;
887
902
} ) ;
888
903
904
+ it ( 'cannot subscribe on connection error' , async ( ) => {
905
+ const liveQueryClient = new LiveQueryClient ( {
906
+ applicationId : 'applicationId' ,
907
+ serverURL : 'ws://test' ,
908
+ javascriptKey : 'javascriptKey' ,
909
+ masterKey : 'masterKey' ,
910
+ sessionToken : 'sessionToken' ,
911
+ } ) ;
912
+ liveQueryClient . socket = {
913
+ send : jest . fn ( ) ,
914
+ } ;
915
+ const query = new ParseQuery ( 'Test' ) ;
916
+ query . equalTo ( 'key' , 'value' ) ;
917
+
918
+ const subscription = liveQueryClient . subscribe ( query ) ;
919
+ liveQueryClient . connectPromise . reject ( new Error ( 'Unable to connect' ) ) ;
920
+ liveQueryClient . connectPromise . catch ( ( ) => { } ) ;
921
+ try {
922
+ await subscription . subscribePromise ;
923
+ expect ( true ) . toBeFalse ( ) ;
924
+ } catch ( e ) {
925
+ expect ( e . message ) . toBe ( 'Unable to connect' ) ;
926
+ }
927
+ } ) ;
928
+
889
929
it ( 'can resubscribe' , async ( ) => {
890
930
const liveQueryClient = new LiveQueryClient ( {
891
931
applicationId : 'applicationId' ,
0 commit comments