@@ -15,6 +15,24 @@ import { MockSocket } from "../__mocks__/ws";
1515const deserializer = mock < Deserializer > ( ) ;
1616
1717describe ( "WebsocketDuplexConnection" , function ( ) {
18+ it ( "reports availability based on open/close status" , ( ) => {
19+ const socket = new MockSocket ( ) as unknown as WebSocket ;
20+ const multiplexerDemultiplexer = mock <
21+ Multiplexer & Demultiplexer & FrameHandler
22+ > ( ) ;
23+ const connection = new WebsocketDuplexConnection (
24+ socket ,
25+ deserializer ,
26+ ( ) => multiplexerDemultiplexer
27+ ) ;
28+
29+ expect ( connection . availability ) . toEqual ( 1 ) ;
30+
31+ connection . close ( ) ;
32+
33+ expect ( connection . availability ) . toEqual ( 0 ) ;
34+ } ) ;
35+
1836 describe ( "when closed" , ( ) => {
1937 it ( "removes listeners from the underlying socket event emitter" , ( ) => {
2038 // arrange
@@ -180,6 +198,22 @@ describe("WebsocketDuplexConnection", function () {
180198 expect ( onCloseCallback ) . toBeCalledTimes ( 1 ) ;
181199 expect ( onCloseCallback ) . toHaveBeenCalledWith ( expectedError ) ;
182200 } ) ;
201+
202+ it ( "reports 0 availability" , ( ) => {
203+ const socket = new MockSocket ( ) as unknown as WebSocket ;
204+ const multiplexerDemultiplexer = mock <
205+ Multiplexer & Demultiplexer & FrameHandler
206+ > ( ) ;
207+ const connection = new WebsocketDuplexConnection (
208+ socket ,
209+ deserializer ,
210+ ( ) => multiplexerDemultiplexer
211+ ) ;
212+
213+ connection . close ( ) ;
214+
215+ expect ( connection . availability ) . toEqual ( 0 ) ;
216+ } ) ;
183217 } ) ;
184218
185219 describe ( "send()" , ( ) => {
0 commit comments