@@ -11,6 +11,10 @@ beforeEach(() => {
11
11
}
12
12
} )
13
13
14
+ // @ts -ignore
15
+ global . WebSocket = jest . fn ( )
16
+ const WebSocket : jest . Mock = global . WebSocket as any
17
+
14
18
global . fetch = jest . fn ( )
15
19
const fetch : jest . Mock = global . fetch as any
16
20
@@ -29,22 +33,40 @@ describe('IntegratorAPI', () => {
29
33
it ( 'should use port 10443 if `https` is set to true' , async ( ) => {
30
34
config . https = true
31
35
const integrator = new IntegratorAPI ( config )
36
+
32
37
fetch . mockImplementationOnce ( ( url ) => {
33
38
expect ( new URL ( url ) . port ) . toBe ( '10443' )
34
39
return new Response ( )
35
40
} )
36
41
42
+ WebSocket . mockImplementation ( ( url ) => {
43
+ expect ( new URL ( url ) . port ) . toBe ( '10443' )
44
+ return { addEventListener : jest . fn ( ) }
45
+ } )
46
+
37
47
await integrator . version ( )
48
+ integrator . connectWS ( ( ) => { } )
49
+
50
+ expect . assertions ( 2 )
38
51
} )
39
- it ( 'should use port 10080 if `https` is set to false' , async ( ) => {
52
+ it ( 'should use port 10088 if `https` is set to false' , async ( ) => {
40
53
config . https = false
41
54
const integrator = new IntegratorAPI ( config )
42
55
43
56
fetch . mockImplementationOnce ( ( url ) => {
44
- expect ( new URL ( url ) . port ) . toBe ( '10080 ' )
57
+ expect ( new URL ( url ) . port ) . toBe ( '10088 ' )
45
58
return new Response ( )
46
59
} )
60
+
61
+ WebSocket . mockImplementation ( ( url ) => {
62
+ expect ( new URL ( url ) . port ) . toBe ( '10088' )
63
+ return { addEventListener : jest . fn ( ) }
64
+ } )
65
+
47
66
await integrator . version ( )
67
+ integrator . connectWS ( ( ) => { } )
68
+
69
+ expect . assertions ( 2 )
48
70
} )
49
71
it ( 'should serialize data to `application/x-www-form-urlencoded` correctly' , async ( ) => {
50
72
const integrator = new IntegratorAPI ( config )
0 commit comments