@@ -93,29 +93,62 @@ describe('RSocketWebSocketClient', () => {
93
93
} ) ;
94
94
95
95
describe ( 'close()' , ( ) => {
96
- it ( 'closes the socket' , ( ) => {
97
- client . close ( ) ;
98
- expect ( socket . close . mock . calls . length ) . toBe ( 1 ) ;
99
- } ) ;
96
+ describe ( 'given an error' , ( ) => {
97
+ it ( 'closes the socket' , ( ) => {
98
+ client . close ( new Error ( ) ) ;
99
+ expect ( socket . close . mock . calls . length ) . toBe ( 1 ) ;
100
+ } ) ;
100
101
101
- it ( 'sets the status to CLOSED' , ( ) => {
102
- let status ;
103
- client . connectionStatus ( ) . subscribe ( {
104
- onNext : _status => ( status = _status ) ,
105
- onSubscribe : subscription =>
106
- subscription . request ( Number . MAX_SAFE_INTEGER ) ,
102
+ it ( 'sets the status to ERROR with the given error' , ( ) => {
103
+ let status ;
104
+ client . connectionStatus ( ) . subscribe ( {
105
+ onNext : _status => ( status = _status ) ,
106
+ onSubscribe : subscription =>
107
+ subscription . request ( Number . MAX_SAFE_INTEGER ) ,
108
+ } ) ;
109
+ const error = new Error ( ) ;
110
+ client . close ( error ) ;
111
+ expect ( status . kind ) . toBe ( 'ERROR' ) ;
112
+ expect ( status . error ) . toBe ( error ) ;
113
+ } ) ;
114
+
115
+ it ( 'calls receive.onError with the given error' , ( ) => {
116
+ const onError = jest . fn ( ) ;
117
+ const onSubscribe = subscription =>
118
+ subscription . request ( Number . MAX_SAFE_INTEGER ) ;
119
+ client . receive ( ) . subscribe ( { onError, onSubscribe} ) ;
120
+ const error = new Error ( ) ;
121
+ client . close ( error ) ;
122
+ expect ( onError . mock . calls . length ) . toBe ( 1 ) ;
123
+ expect ( onError . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
107
124
} ) ;
108
- client . close ( ) ;
109
- expect ( status . kind ) . toBe ( 'CLOSED' ) ;
110
125
} ) ;
111
126
112
- it ( 'calls receive.onComplete' , ( ) => {
113
- const onComplete = jest . fn ( ) ;
114
- const onSubscribe = subscription =>
115
- subscription . request ( Number . MAX_SAFE_INTEGER ) ;
116
- client . receive ( ) . subscribe ( { onComplete, onSubscribe} ) ;
117
- client . close ( ) ;
118
- expect ( onComplete . mock . calls . length ) . toBe ( 1 ) ;
127
+ describe ( 'not given an error' , ( ) => {
128
+ it ( 'closes the socket' , ( ) => {
129
+ client . close ( ) ;
130
+ expect ( socket . close . mock . calls . length ) . toBe ( 1 ) ;
131
+ } ) ;
132
+
133
+ it ( 'sets the status to CLOSED' , ( ) => {
134
+ let status ;
135
+ client . connectionStatus ( ) . subscribe ( {
136
+ onNext : _status => ( status = _status ) ,
137
+ onSubscribe : subscription =>
138
+ subscription . request ( Number . MAX_SAFE_INTEGER ) ,
139
+ } ) ;
140
+ client . close ( ) ;
141
+ expect ( status . kind ) . toBe ( 'CLOSED' ) ;
142
+ } ) ;
143
+
144
+ it ( 'calls receive.onComplete' , ( ) => {
145
+ const onComplete = jest . fn ( ) ;
146
+ const onSubscribe = subscription =>
147
+ subscription . request ( Number . MAX_SAFE_INTEGER ) ;
148
+ client . receive ( ) . subscribe ( { onComplete, onSubscribe} ) ;
149
+ client . close ( ) ;
150
+ expect ( onComplete . mock . calls . length ) . toBe ( 1 ) ;
151
+ } ) ;
119
152
} ) ;
120
153
} ) ;
121
154
0 commit comments