@@ -148,7 +148,6 @@ test ('does not crash when disconnected and trying to send messages', function(t
148148 withClient ( function ( obj ) {
149149 var client = obj . client ;
150150 var mock = obj . mock ;
151- obj . closeWithEnd ( t ) ;
152151
153152 mock . server . on ( 'connection' , function ( ) {
154153 mock . send ( greeting ) ;
@@ -163,6 +162,48 @@ test ('does not crash when disconnected and trying to send messages', function(t
163162 client . say ( '#channel' , 'message2' ) ;
164163 client . end ( ) ;
165164 client . say ( '#channel' , 'message3' ) ;
165+ t . end ( ) ;
166+ } ) ;
167+ } ) ;
168+ } ) ;
169+
170+ test ( 'unhandled messages are emitted appropriately' , function ( t ) {
171+ withClient ( function ( obj ) {
172+ var client = obj . client ;
173+ var mock = obj . mock ;
174+ obj . closeWithEnd ( t ) ;
175+ var endTimeout ;
176+
177+ mock . server . on ( 'connection' , function ( ) {
178+ mock . send ( greeting ) ;
179+ } ) ;
180+
181+ client . on ( 'registered' , function ( ) {
182+ mock . send ( ':127.0.0.1 150 :test\r\n' ) ;
183+ //mock.close();
184+ client . on ( 'error' , function ( ) { console . log ( "error" ) ; } ) ;
185+ client . on ( 'unhandled' , function ( msg ) {
186+ var expected = {
187+ prefix : '127.0.0.1' ,
188+ server : '127.0.0.1' ,
189+ rawCommand : '150' ,
190+ command : '150' ,
191+ commandType : 'normal' ,
192+ args : [ 'test' ]
193+ } ;
194+ t . deepEqual ( msg , expected , 'unhandled message should be emitted as expected' ) ;
195+ client . disconnect ( ) ;
196+ } ) ;
197+ endTimeout = setTimeout ( function ( ) {
198+ if ( t . ended ) return ;
199+ t . ok ( false , 'callback for event must be called' ) ;
200+ client . disconnect ( ) ;
201+ } , 1000 ) ;
202+ } ) ;
203+
204+ client . conn . once ( 'close' , function ( ) {
205+ clearTimeout ( endTimeout )
206+ client . end ( ) ;
166207 } ) ;
167208 } ) ;
168209} ) ;
0 commit comments