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