/
plugins-test.js
43 lines (37 loc) · 1.15 KB
/
plugins-test.js
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
const { Octokit } = require("../../");
require("../mocha-node-setup");
describe("plugins", () => {
it("gets called in constructor", () => {
const MyOctokit = Octokit.plugin(octokit => {
octokit.foo = "bar";
});
const myClient = new MyOctokit();
expect(myClient.foo).to.equal("bar");
});
it("does not override plugins of original constructor", () => {
const MyOctokit = Octokit.plugin(octokit => {
octokit.foo = "bar";
});
const myClient = new MyOctokit();
expect(myClient.foo).to.equal("bar");
const octokit = new Octokit();
expect(octokit.foo).to.equal(undefined);
});
it("receives client options", () => {
const MyOctokit = Octokit.plugin((octokit, options) => {
expect(options.foo).to.equal("bar");
});
MyOctokit({ foo: "bar" });
});
it("does not load the same plugin more than once", () => {
const myPlugin = (octokit, options) => {
if (octokit.customKey) {
throw new Error("Boom!");
} else {
octokit.customKey = true;
}
};
const MyOctokit = Octokit.plugin(myPlugin).plugin(myPlugin);
expect(MyOctokit).to.not.throw();
});
});