forked from octokit/core.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.test.ts
73 lines (60 loc) · 2.18 KB
/
log.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { jest } from "@jest/globals";
describe("octokit.log", () => {
it(".debug() and .info() are no-ops by default", async () => {
const calls: String[] = [];
const debug = jest
.spyOn(console, "debug")
.mockImplementation(() => calls.push("debug"));
const info = jest
.spyOn(console, "info")
.mockImplementation(() => calls.push("info"));
const warn = jest
.spyOn(console, "warn")
.mockImplementation(() => calls.push("warn"));
const error = jest
.spyOn(console, "error")
.mockImplementation(() => calls.push("error"));
const Octokit = (await import("../src/index.ts")).Octokit;
const octokit = new Octokit();
octokit.log.debug("foo");
octokit.log.info("bar");
octokit.log.warn("baz");
octokit.log.error("daz");
expect(octokit.log.debug.name).toBe("noop");
expect(octokit.log.info.name).toBe("noop");
expect(debug).toHaveBeenCalledTimes(0);
expect(info).toHaveBeenCalledTimes(0);
expect(warn).toHaveBeenCalledTimes(1);
expect(error).toHaveBeenCalledTimes(1);
expect(calls).toStrictEqual(["warn", "error"]);
debug.mockRestore();
info.mockRestore();
warn.mockRestore();
error.mockRestore();
});
it("has .debug(), .info(), .warn(), and .error() functions", async () => {
const Octokit = (await import("../src/index.ts")).Octokit;
const octokit = new Octokit();
expect(typeof octokit.log.debug).toBe("function");
expect(typeof octokit.log.info).toBe("function");
expect(typeof octokit.log.warn).toBe("function");
expect(typeof octokit.log.error).toBe("function");
});
it("all .log.*() methods can be overwritten", async () => {
const Octokit = (await import("../src/index.ts")).Octokit;
const calls: String[] = [];
const octokit = new Octokit({
log: {
debug: () => calls.push("debug"),
info: () => calls.push("info"),
warn: () => calls.push("warn"),
error: () => calls.push("error"),
},
});
octokit.log.debug("foo");
octokit.log.info("bar");
octokit.log.warn("baz");
octokit.log.error("daz");
expect(calls).toStrictEqual(["debug", "info", "warn", "error"]);
});
});