forked from adamlaska/core.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.test.ts
More file actions
58 lines (47 loc) · 1.69 KB
/
log.test.ts
File metadata and controls
58 lines (47 loc) · 1.69 KB
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
import { Octokit } from "../src";
describe("octokit.log", () => {
it("has .debug(), .info(), .warn(), and .error() functions", () => {
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(".debug() and .info() are no-ops by default", () => {
const originalLogDebug = console.debug;
const originalLogInfo = console.info;
const originalLogWarn = console.warn;
const originalLogError = console.error;
const calls: String[] = [];
console.debug = () => calls.push("debug");
console.info = () => calls.push("info");
console.warn = () => calls.push("warn");
console.error = () => calls.push("error");
const octokit = new Octokit();
octokit.log.debug("foo");
octokit.log.info("bar");
octokit.log.warn("baz");
octokit.log.error("daz");
console.debug = originalLogDebug;
console.info = originalLogInfo;
console.warn = originalLogWarn;
console.error = originalLogError;
expect(calls).toStrictEqual(["warn", "error"]);
});
it("all .log.*() methods can be overwritten", () => {
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"]);
});
});