@@ -5,8 +5,7 @@ import { fixRequestBody } from './fixRequestBody';
5
5
6
6
const fakeProxyRequest = ( ) => {
7
7
const proxyRequest = new http . ClientRequest ( 'http://some-host' ) ;
8
- proxyRequest . emit = jest . fn ( ) ;
9
-
8
+ proxyRequest . emit = ( ) => false ; // Otherwise we get "Error: getaddrinfo ENOTFOUND some-host"
10
9
return proxyRequest ;
11
10
} ;
12
11
@@ -16,12 +15,7 @@ test('should not write when body is undefined', () => {
16
15
jest . spyOn ( proxyRequest , 'setHeader' ) ;
17
16
jest . spyOn ( proxyRequest , 'write' ) ;
18
17
19
- fixRequestBody (
20
- proxyRequest ,
21
- { body : undefined } as express . Request ,
22
- { } as http . ServerResponse ,
23
- { }
24
- ) ;
18
+ fixRequestBody ( proxyRequest , { body : undefined } as express . Request ) ;
25
19
26
20
expect ( proxyRequest . setHeader ) . not . toHaveBeenCalled ( ) ;
27
21
expect ( proxyRequest . write ) . not . toHaveBeenCalled ( ) ;
@@ -33,7 +27,7 @@ test('should not write when body is empty', () => {
33
27
jest . spyOn ( proxyRequest , 'setHeader' ) ;
34
28
jest . spyOn ( proxyRequest , 'write' ) ;
35
29
36
- fixRequestBody ( proxyRequest , { body : { } } as express . Request , { } as http . ServerResponse , { } ) ;
30
+ fixRequestBody ( proxyRequest , { body : { } } as express . Request ) ;
37
31
38
32
expect ( proxyRequest . setHeader ) . not . toHaveBeenCalled ( ) ;
39
33
expect ( proxyRequest . write ) . not . toHaveBeenCalled ( ) ;
@@ -46,12 +40,7 @@ test('should write when body is not empty and Content-Type is application/json',
46
40
jest . spyOn ( proxyRequest , 'setHeader' ) ;
47
41
jest . spyOn ( proxyRequest , 'write' ) ;
48
42
49
- fixRequestBody (
50
- proxyRequest ,
51
- { body : { someField : 'some value' } } as express . Request ,
52
- { } as http . ServerResponse ,
53
- { }
54
- ) ;
43
+ fixRequestBody ( proxyRequest , { body : { someField : 'some value' } } as express . Request ) ;
55
44
56
45
const expectedBody = JSON . stringify ( { someField : 'some value' } ) ;
57
46
expect ( proxyRequest . setHeader ) . toHaveBeenCalledWith ( 'Content-Length' , expectedBody . length ) ;
@@ -65,14 +54,9 @@ test('should write when body is not empty and Content-Type is application/x-www-
65
54
jest . spyOn ( proxyRequest , 'setHeader' ) ;
66
55
jest . spyOn ( proxyRequest , 'write' ) ;
67
56
68
- fixRequestBody (
69
- proxyRequest ,
70
- { body : { someField : 'some value' } } as express . Request ,
71
- { } as http . ServerResponse ,
72
- { }
73
- ) ;
57
+ fixRequestBody ( proxyRequest , { body : { someField : 'some value' } } as express . Request ) ;
74
58
75
- const expectedBody = new URLSearchParams ( { someField : ' some value' } ) . toString ( ) ;
59
+ const expectedBody = 'someField= some+ value';
76
60
expect ( proxyRequest . setHeader ) . toHaveBeenCalledWith ( 'Content-Length' , expectedBody . length ) ;
77
61
expect ( proxyRequest . write ) . toHaveBeenCalledWith ( expectedBody ) ;
78
62
} ) ;
0 commit comments