-
Notifications
You must be signed in to change notification settings - Fork 302
/
plugin.test.ts
68 lines (60 loc) · 1.82 KB
/
plugin.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
import { Octokit } from "../src";
const pluginFoo = () => {
return { foo: "bar" };
};
const pluginBaz = () => {
return { baz: "daz" };
};
const pluginQaz = () => {
return { qaz: "naz" };
};
describe("Octokit.plugin()", () => {
it("gets called in constructor", () => {
const MyOctokit = Octokit.plugin(pluginFoo);
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
});
it("supports multiple plugins", () => {
const MyOctokit = Octokit.plugin(pluginFoo, pluginBaz, pluginQaz);
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
expect(myClient.baz).toEqual("daz");
expect(myClient.qaz).toEqual("naz");
});
it("does not override plugins of original constructor", () => {
const MyOctokit = Octokit.plugin(pluginFoo);
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
const octokit = new Octokit();
expect(octokit).not.toHaveProperty("foo");
});
it("receives client options", () => {
const MyOctokit = Octokit.plugin((_octokit, options) => {
expect(options).toStrictEqual({
foo: "bar",
});
});
new MyOctokit({ foo: "bar" });
});
it("does not load the same plugin more than once", () => {
const myPlugin = (octokit: Octokit) => {
if ("customKey" in octokit) {
throw new Error("Boom!");
}
return {
customKey: true,
};
};
const MyOctokit = Octokit.plugin(myPlugin).plugin(myPlugin);
expect(() => new MyOctokit()).not.toThrow();
});
it("supports chaining", () => {
const MyOctokit = Octokit.plugin(pluginFoo)
.plugin(pluginBaz)
.plugin(pluginQaz);
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
expect(myClient.baz).toEqual("daz");
expect(myClient.qaz).toEqual("naz");
});
});