-
Notifications
You must be signed in to change notification settings - Fork 910
/
Copy pathstatusPageMiddleware.test.ts
45 lines (35 loc) · 1.29 KB
/
statusPageMiddleware.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import http from 'http';
import statusPageMiddleware from './../statusPageMiddleware';
describe('statusPageMiddleware', () => {
let res: jest.Mocked<http.ServerResponse>;
let mockReq: http.IncomingMessage;
beforeEach(() => {
res = {
setHeader: jest.fn(),
end: jest.fn(),
} as any;
mockReq = {} as any;
});
afterEach(() => {
jest.restoreAllMocks();
});
it('should set headers and end the response', () => {
jest.spyOn(process, 'cwd').mockReturnValue('/mocked/path');
statusPageMiddleware(mockReq, res);
// We're strictly checking response here, because React Native is strongly depending on this response. Changing the response might be a breaking change.
expect(res.setHeader).toHaveBeenCalledWith(
'X-React-Native-Project-Root',
'/mocked/path',
);
expect(res.end).toHaveBeenCalledWith('packager-status:running');
});
it('should set headers and end the response with decoded value', () => {
jest.spyOn(process, 'cwd').mockReturnValue('/привіт/path');
statusPageMiddleware(mockReq, res);
expect(res.setHeader).toHaveBeenCalledWith(
'X-React-Native-Project-Root',
'/%D0%BF%D1%80%D0%B8%D0%B2%D1%96%D1%82/path',
);
expect(res.end).toHaveBeenCalledWith('packager-status:running');
});
});