forked from adamlaska/core.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.test.ts
More file actions
84 lines (75 loc) · 1.93 KB
/
plugin.test.ts
File metadata and controls
84 lines (75 loc) · 1.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Octokit } from "../src";
describe("Octokit.plugin()", () => {
it("gets called in constructor", () => {
const MyOctokit = Octokit.plugin(() => {
return {
foo: "bar"
};
});
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
});
it("supports array of plugins", () => {
const MyOctokit = Octokit.plugin([
() => {
return {
foo: "bar"
};
},
() => {
return { baz: "daz" };
}
]);
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
expect(myClient.baz).toEqual("daz");
});
it("does not override plugins of original constructor", () => {
const MyOctokit = Octokit.plugin(octokit => {
return {
foo: "bar"
};
});
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(() => {
return {
foo: "bar"
};
})
.plugin(() => {
return { baz: "daz" };
})
.plugin(() => {
return { qaz: "naz" };
});
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
expect(myClient.baz).toEqual("daz");
expect(myClient.qaz).toEqual("naz");
});
});