This repository was archived by the owner on Dec 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathisEnabledForJavascript.test.ts
79 lines (70 loc) · 2.65 KB
/
isEnabledForJavascript.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
69
70
71
72
73
74
75
76
77
78
79
(global as any).nova = Object.assign(nova, {
commands: {
invoke: jest.fn(),
},
config: {
onDidChange: jest.fn(),
["get"]: jest.fn(),
},
workspace: {
config: { onDidChange: jest.fn(), ["get"]: jest.fn() },
},
});
describe("isEnabledForJavascript", () => {
beforeEach(() => {
(nova.workspace.config.get as jest.Mock).mockReset();
(nova.config.get as jest.Mock).mockReset();
});
const { isEnabledForJavascript } = require("./isEnabledForJavascript");
describe("reloads extension when it changes", () => {
it("globally and for the workspace", () => {
expect(nova.config.onDidChange).toBeCalledTimes(1);
expect(nova.config.onDidChange).toBeCalledWith(
"apexskier.typescript.config.isEnabledForJavascript",
expect.any(Function)
);
expect(nova.workspace.config.onDidChange).toBeCalledTimes(1);
expect(nova.workspace.config.onDidChange).toBeCalledWith(
"apexskier.typescript.config.isEnabledForJavascript",
expect.any(Function)
);
// same function
const onWorkspaceChange = (nova.workspace.config.onDidChange as jest.Mock)
.mock.calls[0][1];
const onGlobalChange = (nova.config.onDidChange as jest.Mock).mock
.calls[0][1];
expect(onWorkspaceChange).toBe(onGlobalChange);
});
it("by calling the reload command", () => {
const reload = (nova.config.onDidChange as jest.Mock).mock.calls[0][1];
reload();
expect(nova.commands.invoke).toBeCalledTimes(1);
expect(nova.commands.invoke).toBeCalledWith(
"apexskier.typescript.reload"
);
});
});
describe("is true by default", () => {
expect(isEnabledForJavascript()).toBe(true);
});
describe("can be disabled globally", () => {
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null);
(nova.config.get as jest.Mock).mockReturnValueOnce(false);
expect(isEnabledForJavascript()).toBe(false);
});
describe("can be enabled globally", () => {
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null);
(nova.config.get as jest.Mock).mockReturnValueOnce(true);
expect(isEnabledForJavascript()).toBe(true);
});
describe("can be disabled in the workspace", () => {
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce("Disable");
(nova.config.get as jest.Mock).mockReturnValueOnce(true);
expect(isEnabledForJavascript()).toBe(false);
});
describe("can be enabled in the workspace", () => {
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce("Enable");
(nova.config.get as jest.Mock).mockReturnValueOnce(false);
expect(isEnabledForJavascript()).toBe(true);
});
});