@@ -138,23 +138,38 @@ describe('IncomingWebSocket', () => {
138138 describe ( '#close' , ( ) => {
139139 let terminateSpy ;
140140 let closeSpy ;
141- before ( ( ) => {
141+ beforeEach ( ( ) => {
142142 terminateSpy = spy ( ) ;
143143 closeSpy = spy ( ) ;
144144 incomingWs . socket . terminate = terminateSpy ;
145145 incomingWs . socket . close = closeSpy ;
146- incomingWs . close ( 1001 , 'msg' ) ;
147146 } ) ;
148147
149- it ( 'should close the websocket' , ( ) => {
148+ it ( 'should close and terminate the websocket when code is >= 1000 and < 1004' , ( ) => {
149+ incomingWs . close ( 1001 , 'msg' ) ;
150150 assert ( closeSpy . calledWith ( 1001 , 'msg' ) ) ;
151+ assert ( terminateSpy . calledOnce ) ;
152+ } ) ;
153+
154+ it ( 'should not call close, only terminate the websocket when code is 1005' , ( ) => {
155+ incomingWs . close ( 1005 , 'msg' ) ;
156+ assert . isFalse ( closeSpy . called ) ;
157+ assert ( terminateSpy . calledOnce ) ;
158+ } ) ;
159+
160+ it ( 'should not call close, only terminate the websocket when code is 1006' , ( ) => {
161+ incomingWs . close ( 1006 , 'msg' ) ;
162+ assert . isFalse ( closeSpy . called ) ;
163+ assert ( terminateSpy . calledOnce ) ;
151164 } ) ;
152165
153166 it ( 'should terminate the websocket' , ( ) => {
167+ incomingWs . close ( 1001 , 'msg' ) ;
154168 assert ( terminateSpy . calledOnce ) ;
155169 } ) ;
156170
157171 it ( 'should set teardown to true' , ( ) => {
172+ incomingWs . close ( 1001 , 'msg' ) ;
158173 expect ( incomingWs . teardown ) . to . equal ( true ) ;
159174 } ) ;
160175 } ) ;
0 commit comments