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
57 lines (51 loc) · 1.47 KB
/
plugin.test.ts
File metadata and controls
57 lines (51 loc) · 1.47 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
import { Octokit } from "../src";
describe("Octokit.plugin()", () => {
it("gets called in constructor", () => {
const MyOctokit = Octokit.plugin(octokit => {
octokit.foo = "bar";
});
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
});
it("supports array of plugins", () => {
const MyOctokit = Octokit.plugin([
octokit => {
octokit.foo = "bar";
},
octokit => {
octokit.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 => {
octokit.foo = "bar";
});
const myClient = new MyOctokit();
expect(myClient.foo).toEqual("bar");
const octokit = new Octokit();
expect(octokit.foo).toEqual(undefined);
});
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 (octokit.customKey) {
throw new Error("Boom!");
} else {
octokit.customKey = true;
}
};
const MyOctokit = Octokit.plugin(myPlugin).plugin(myPlugin);
expect(() => new MyOctokit()).not.toThrow();
});
});