@@ -3,21 +3,21 @@ import initWebSocketPolyfill from '../../services/WebSocketPolyfill.js'
33describe ( 'Init function' , ( ) => {
44
55 it ( 'returns a websocket polyfill class' , ( ) => {
6- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
6+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
77 const Polyfill = initWebSocketPolyfill ( syncService )
88 const websocket = new Polyfill ( 'url' )
99 expect ( websocket ) . toBeInstanceOf ( Polyfill )
1010 } )
1111
1212 it ( 'registers handlers' , ( ) => {
13- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
13+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
1414 const Polyfill = initWebSocketPolyfill ( syncService )
1515 const websocket = new Polyfill ( 'url' )
1616 expect ( syncService . on ) . toHaveBeenCalled ( )
1717 } )
1818
1919 it ( 'opens sync service' , ( ) => {
20- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
20+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
2121 const fileId = 123
2222 const initialSession = { }
2323 const Polyfill = initWebSocketPolyfill ( syncService , fileId , initialSession )
@@ -28,7 +28,7 @@ describe('Init function', () => {
2828 it ( 'sends steps to sync service' , async ( ) => {
2929 const syncService = {
3030 on : jest . fn ( ) ,
31- open : jest . fn ( ) ,
31+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
3232 sendSteps : async getData => getData ( ) ,
3333 }
3434 const queue = [ 'initial' ]
@@ -46,9 +46,10 @@ describe('Init function', () => {
4646 } )
4747
4848 it ( 'handles early reject' , async ( ) => {
49+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
4950 const syncService = {
5051 on : jest . fn ( ) ,
51- open : jest . fn ( ) ,
52+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
5253 sendSteps : jest . fn ( ) . mockRejectedValue ( 'error before reading steps in sync service' ) ,
5354 }
5455 const queue = [ 'initial' ]
@@ -64,9 +65,10 @@ describe('Init function', () => {
6465 } )
6566
6667 it ( 'handles reject after reading data' , async ( ) => {
68+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
6769 const syncService = {
6870 on : jest . fn ( ) ,
69- open : jest . fn ( ) ,
71+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
7072 sendSteps : jest . fn ( ) . mockImplementation ( async getData => {
7173 getData ( )
7274 throw 'error when sending in sync service'
@@ -85,9 +87,10 @@ describe('Init function', () => {
8587 } )
8688
8789 it ( 'queue survives a close' , async ( ) => {
90+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
8891 const syncService = {
8992 on : jest . fn ( ) ,
90- open : jest . fn ( ) ,
93+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
9194 sendSteps : jest . fn ( ) . mockImplementation ( async getData => {
9295 getData ( )
9396 throw 'error when sending in sync service'
0 commit comments