-
Notifications
You must be signed in to change notification settings - Fork 12
/
responseHandler.test.js
53 lines (39 loc) · 1.17 KB
/
responseHandler.test.js
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
46
47
48
49
50
51
52
53
import ResponseHandler from './responseHandler';
describe('ResponseHandler', () => {
let responseHandler;
beforeEach(() => {
responseHandler = new ResponseHandler();
});
it('should have 1 handler', () => {
responseHandler.add('1', null);
expect(responseHandler.handlers).toHaveLength(1);
});
it('should handle multiple handlers with same code', () => {
const mockCallback = jest.fn();
responseHandler.add(120, mockCallback);
responseHandler.add(120, mockCallback);
responseHandler.handle({
status: 120,
});
expect(mockCallback.mock.calls.length).toBe(2);
});
it('should fallback to series', () => {
const seriesCb = jest.fn();
responseHandler.add(400, seriesCb);
responseHandler.handle({
status: 404,
});
expect(seriesCb.mock.calls.length).toBe(1);
});
it('should fallback to 0', () => {
const mockCallback = jest.fn();
responseHandler.add(0, mockCallback);
responseHandler.add(500, null);
responseHandler.add(301, null);
responseHandler.add(609, null);
responseHandler.handle({
status: 404,
});
expect(mockCallback.mock.calls.length).toBe(1);
});
});