-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.js
45 lines (39 loc) · 1.04 KB
/
index.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
const sut = require(".");
describe("Redirect", () => {
test("When not given res, should throw error", () => {
// Arrange
// Act
expect(() => sut())
// Assert
.toThrowError("Response object required");
});
test("When not given status code, should throw error", () => {
// Arrange
// Act
expect(() => sut({}))
// Assert
.toThrowError("Status code required");
});
test("When not given location, should throw error", () => {
// Arrange
// Act
expect(() => sut({}, 300))
// Assert
.toThrowError("Location required");
});
test("When given all args, should set statusCode and location", () => {
// Arrange
const statusCode = 302;
const location = "http://google.com";
const res = {
setHeader: jest.fn(),
end: jest.fn()
};
// Act
sut(res, statusCode, location);
// Assert
expect(res.statusCode).toBe(statusCode);
expect(res.setHeader).toHaveBeenCalledWith("Location", location);
expect(res.end).toHaveBeenCalled();
});
});