@@ -8,21 +8,21 @@ import initWebSocketPolyfill from '../../services/WebSocketPolyfill.js'
8
8
describe ( 'Init function' , ( ) => {
9
9
10
10
it ( 'returns a websocket polyfill class' , ( ) => {
11
- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
11
+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
12
12
const Polyfill = initWebSocketPolyfill ( syncService )
13
13
const websocket = new Polyfill ( 'url' )
14
14
expect ( websocket ) . toBeInstanceOf ( Polyfill )
15
15
} )
16
16
17
17
it ( 'registers handlers' , ( ) => {
18
- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
18
+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
19
19
const Polyfill = initWebSocketPolyfill ( syncService )
20
20
const websocket = new Polyfill ( 'url' )
21
21
expect ( syncService . on ) . toHaveBeenCalled ( )
22
22
} )
23
23
24
24
it ( 'opens sync service' , ( ) => {
25
- const syncService = { on : jest . fn ( ) , open : jest . fn ( ) }
25
+ const syncService = { on : jest . fn ( ) , open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) }
26
26
const fileId = 123
27
27
const initialSession = { }
28
28
const Polyfill = initWebSocketPolyfill ( syncService , fileId , initialSession )
@@ -33,7 +33,7 @@ describe('Init function', () => {
33
33
it ( 'sends steps to sync service' , async ( ) => {
34
34
const syncService = {
35
35
on : jest . fn ( ) ,
36
- open : jest . fn ( ) ,
36
+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
37
37
sendSteps : async getData => getData ( ) ,
38
38
}
39
39
const queue = [ 'initial' ]
@@ -51,9 +51,10 @@ describe('Init function', () => {
51
51
} )
52
52
53
53
it ( 'handles early reject' , async ( ) => {
54
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
54
55
const syncService = {
55
56
on : jest . fn ( ) ,
56
- open : jest . fn ( ) ,
57
+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
57
58
sendSteps : jest . fn ( ) . mockRejectedValue ( 'error before reading steps in sync service' ) ,
58
59
}
59
60
const queue = [ 'initial' ]
@@ -69,9 +70,10 @@ describe('Init function', () => {
69
70
} )
70
71
71
72
it ( 'handles reject after reading data' , async ( ) => {
73
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
72
74
const syncService = {
73
75
on : jest . fn ( ) ,
74
- open : jest . fn ( ) ,
76
+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
75
77
sendSteps : jest . fn ( ) . mockImplementation ( async getData => {
76
78
getData ( )
77
79
throw 'error when sending in sync service'
@@ -90,9 +92,10 @@ describe('Init function', () => {
90
92
} )
91
93
92
94
it ( 'queue survives a close' , async ( ) => {
95
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
93
96
const syncService = {
94
97
on : jest . fn ( ) ,
95
- open : jest . fn ( ) ,
98
+ open : jest . fn ( ( ) => Promise . resolve ( { version : 123 , session : { } } ) ) ,
96
99
sendSteps : jest . fn ( ) . mockImplementation ( async getData => {
97
100
getData ( )
98
101
throw 'error when sending in sync service'
0 commit comments