|
1 |
| -import { Octokit } from "../src"; |
2 |
| - |
3 | 1 | describe("octokit.log", () => {
|
4 |
| - it("has .debug(), .info(), .warn(), and .error() functions", () => { |
5 |
| - const octokit = new Octokit(); |
6 |
| - expect(typeof octokit.log.debug).toBe("function"); |
7 |
| - expect(typeof octokit.log.info).toBe("function"); |
8 |
| - expect(typeof octokit.log.warn).toBe("function"); |
9 |
| - expect(typeof octokit.log.error).toBe("function"); |
10 |
| - }); |
| 2 | + it(".debug() and .info() are no-ops by default", async () => { |
| 3 | + const calls: String[] = []; |
| 4 | + |
| 5 | + const debug = jest |
| 6 | + .spyOn(console, "debug") |
| 7 | + .mockImplementation(() => calls.push("debug")); |
| 8 | + const info = jest |
| 9 | + .spyOn(console, "info") |
| 10 | + .mockImplementation(() => calls.push("info")); |
| 11 | + const warn = jest |
| 12 | + .spyOn(console, "warn") |
| 13 | + .mockImplementation(() => calls.push("warn")); |
| 14 | + const error = jest |
| 15 | + .spyOn(console, "error") |
| 16 | + .mockImplementation(() => calls.push("error")); |
| 17 | + const Octokit = (await import("../src")).Octokit; |
11 | 18 |
|
12 |
| - it(".debug() and .info() are no-ops by default", () => { |
13 | 19 | const octokit = new Octokit();
|
14 | 20 |
|
| 21 | + octokit.log.debug("foo"); |
| 22 | + octokit.log.info("bar"); |
| 23 | + octokit.log.warn("baz"); |
| 24 | + octokit.log.error("daz"); |
| 25 | + |
15 | 26 | expect(octokit.log.debug.name).toBe("noop");
|
16 | 27 | expect(octokit.log.info.name).toBe("noop");
|
17 | 28 |
|
18 |
| - octokit.log.debug("foo"); |
19 |
| - octokit.log.info("bar"); |
| 29 | + expect(debug).toHaveBeenCalledTimes(0); |
| 30 | + expect(info).toHaveBeenCalledTimes(0); |
| 31 | + expect(warn).toHaveBeenCalledTimes(1); |
| 32 | + expect(error).toHaveBeenCalledTimes(1); |
| 33 | + expect(calls).toStrictEqual(["warn", "error"]); |
| 34 | + |
| 35 | + debug.mockRestore(); |
| 36 | + info.mockRestore(); |
| 37 | + warn.mockRestore(); |
| 38 | + error.mockRestore(); |
| 39 | + }); |
| 40 | + |
| 41 | + it("has .debug(), .info(), .warn(), and .error() functions", async () => { |
| 42 | + const Octokit = (await import("../src")).Octokit; |
| 43 | + |
| 44 | + const octokit = new Octokit(); |
| 45 | + expect(typeof octokit.log.debug).toBe("function"); |
| 46 | + expect(typeof octokit.log.info).toBe("function"); |
| 47 | + expect(typeof octokit.log.warn).toBe("function"); |
| 48 | + expect(typeof octokit.log.error).toBe("function"); |
20 | 49 | });
|
21 | 50 |
|
22 |
| - it("all .log.*() methods can be overwritten", () => { |
| 51 | + it("all .log.*() methods can be overwritten", async () => { |
| 52 | + const Octokit = (await import("../src")).Octokit; |
23 | 53 | const calls: String[] = [];
|
24 | 54 |
|
25 | 55 | const octokit = new Octokit({
|
|
0 commit comments