@@ -360,6 +360,67 @@ describe('WebSocketChannel', () => {
360360 } )
361361 } )
362362
363+ describe ( '.startReceiveTimeout()' , ( ) => {
364+ let fakeSetTimeout
365+ beforeEach ( ( ) => {
366+ const address = ServerAddress . fromUrl ( 'http://localhost:8989' )
367+ const channelConfig = new ChannelConfig (
368+ address ,
369+ { connectionTimeout : 0 } ,
370+ SERVICE_UNAVAILABLE
371+ )
372+ webSocketChannel = new WebSocketChannel (
373+ channelConfig ,
374+ undefined ,
375+ createWebSocketFactory ( WS_OPEN )
376+ )
377+ fakeSetTimeout = setTimeoutMock . install ( )
378+ fakeSetTimeout . pause ( )
379+ } )
380+
381+ afterEach ( ( ) => {
382+ fakeSetTimeout . uninstall ( )
383+ } )
384+
385+ describe ( 'receive timeout is setup' , ( ) => {
386+ const receiveTimeout = 1000
387+ beforeEach ( ( ) => {
388+ webSocketChannel . setupReceiveTimeout ( receiveTimeout )
389+ } )
390+
391+ it ( 'should call setTimeout(receiveTimeout) when it call first' , ( ) => {
392+ webSocketChannel . startReceiveTimeout ( )
393+
394+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
395+ expect ( fakeSetTimeout . invocationDelays ) . toEqual ( [ receiveTimeout ] )
396+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
397+ } )
398+
399+ it ( 'should call not setTimeout(receiveTimeout) when already started' , ( ) => {
400+ webSocketChannel . startReceiveTimeout ( )
401+
402+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
403+ expect ( fakeSetTimeout . invocationDelays ) . toEqual ( [ receiveTimeout ] )
404+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
405+
406+ // webSocketChannel.startReceiveTimeout()
407+
408+ // expect(fakeSetTimeout._timeoutIdCounter).toEqual(1)
409+ // expect(fakeSetTimeout.invocationDelays).toEqual([receiveTimeout])
410+ // expect(fakeSetTimeout.clearedTimeouts).toEqual([])
411+ } )
412+ } )
413+
414+ describe ( 'receive timeout is not setup' , ( ) => {
415+ it ( 'should not call setTimeout(receiveTimeout) when not configured' , ( ) => {
416+ // start
417+ webSocketChannel . startReceiveTimeout ( )
418+
419+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 0 )
420+ } )
421+ } )
422+ } )
423+
363424 function createWebSocketFactory ( readyState ) {
364425 const ws = { }
365426 ws . readyState = readyState
0 commit comments