@@ -354,7 +354,6 @@ describe('integration tests for callback style', () => {
354354 expect ( err ) . toBe ( null ) ;
355355 expect ( data ) . toBeInstanceOf ( Array ) ;
356356 expect ( data . filter ( a => a ) . length ) . toBe ( 3 ) ;
357- console . log ( data ) ;
358357 data . forEach ( msg => expect ( / O K / . test ( msg ) ) . toBe ( true ) ) ;
359358 client . rset ( ( err ) => {
360359 expect ( err ) . toBe ( null ) ;
@@ -479,4 +478,46 @@ describe('integration tests for callback style', () => {
479478 } ) ;
480479 } ) ;
481480 } ) ;
481+
482+ describe ( 'double connect' , ( ) => {
483+ it ( 'should not emit an error' , ( done ) => {
484+ const client = new Client ( tlsOptions ) ;
485+ client . connect ( ( err ) => {
486+ expect ( err ) . toBe ( null ) ;
487+ client . connect ( ( err ) => {
488+ expect ( err ) . toBe ( null ) ;
489+ client . disconnect ( done ) ;
490+ } ) ;
491+ } ) ;
492+ } ) ;
493+ } ) ;
494+
495+ describe ( 'socket error event' , ( ) => {
496+ it ( 'should return an error in the callback function' , ( done ) => {
497+ let notConnected = true ;
498+ const error = new Error ( 'error' ) ;
499+ const client = new Client ( tlsOptions ) ;
500+ client . connect ( ( err ) => {
501+ if ( notConnected ) {
502+ notConnected = false ;
503+ expect ( err ) . toBe ( null ) ;
504+ client . _socket . emit ( 'error' , error ) ;
505+ } else {
506+ expect ( err ) . toBe ( error ) ;
507+ client . disconnect ( done ) ;
508+ }
509+ } ) ;
510+ } ) ;
511+ } ) ;
512+
513+ describe ( 'socket error event' , ( ) => {
514+ it ( 'should rejects in promise' , async ( ) => {
515+ const error = new Error ( 'error' ) ;
516+ const client = new Client ( tlsOptions ) ;
517+ client . retrieve = jest . fn ( ( _ , cb ) => cb ( error ) ) ;
518+ await client . connect ( ) ;
519+ expect ( client . retrieveAndDeleteAll ( ) ) . rejects . toEqual ( error ) ;
520+ client . quit ( ) ;
521+ } ) ;
522+ } ) ;
482523} ) ;
0 commit comments