Skip to content

Commit f57f9db

Browse files
committed
test(plugin-completions): update test
1 parent 8d77220 commit f57f9db

2 files changed

Lines changed: 22 additions & 46 deletions

File tree

packages/plugin-completions/test/commands.test.ts

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,21 @@ describe("plugin-completions/commands", () => {
3535
});
3636

3737
it("should throw error if shell is missing", async () => {
38-
const cli = TestBaseCli().use(completionsPlugin());
39-
const errorFn = vi.fn();
40-
cli.errorHandler(errorFn);
41-
42-
await cli.parse(["completions", "install"]);
43-
44-
await new Promise((resolve) => setTimeout(resolve, 10));
45-
46-
expect(errorFn).toHaveBeenCalled();
47-
expect(errorFn.mock.calls[0][0].message).toContain(
48-
"Please specify the shell type",
49-
);
38+
await expect(async () => {
39+
await TestBaseCli()
40+
.use(completionsPlugin())
41+
.parse(["completions", "install"]);
42+
}).rejects.toThrow("Please specify the shell type");
5043
});
5144

5245
it("should throw error if shell is unsupported", async () => {
53-
const cli = TestBaseCli().use(completionsPlugin());
54-
const errorFn = vi.fn();
55-
cli.errorHandler(errorFn);
56-
57-
await cli.parse(["completions", "install", "--shell", "invalid"]);
58-
59-
await new Promise((resolve) => setTimeout(resolve, 10));
60-
61-
expect(errorFn).toHaveBeenCalled();
62-
expect(errorFn.mock.calls[0][0].message).toContain("Unsupported shell");
46+
await expect(async () => {
47+
await TestBaseCli()
48+
.use(completionsPlugin())
49+
.parse(["completions", "install", "--shell", "invalid"]);
50+
}).rejects.toThrowErrorMatchingInlineSnapshot(
51+
"[Error: Invalid value: invalid. Must be one of: bash, zsh, fish]",
52+
);
6353
});
6454
});
6555

@@ -93,31 +83,19 @@ describe("plugin-completions/commands", () => {
9383
});
9484

9585
it("should throw error if shell is missing", async () => {
96-
const cli = TestBaseCli().use(completionsPlugin());
97-
const errorFn = vi.fn();
98-
cli.errorHandler(errorFn);
99-
100-
await cli.parse(["completions"]);
101-
102-
await new Promise((resolve) => setTimeout(resolve, 10));
103-
104-
expect(errorFn).toHaveBeenCalled();
105-
expect(errorFn.mock.calls[0][0].message).toContain(
106-
"Please specify the shell type",
107-
);
86+
await expect(async () => {
87+
await TestBaseCli().use(completionsPlugin()).parse(["completions"]);
88+
}).rejects.toThrow("Please specify the shell type");
10889
});
10990

11091
it("should throw error if shell is unsupported", async () => {
111-
const cli = TestBaseCli().use(completionsPlugin());
112-
const errorFn = vi.fn();
113-
cli.errorHandler(errorFn);
114-
115-
await cli.parse(["completions", "--shell", "invalid"]);
116-
117-
await new Promise((resolve) => setTimeout(resolve, 10));
118-
119-
expect(errorFn).toHaveBeenCalled();
120-
expect(errorFn.mock.calls[0][0].message).toContain("Unsupported shell");
92+
await expect(async () => {
93+
await TestBaseCli()
94+
.use(completionsPlugin())
95+
.parse(["completions", "--shell", "invalid"]);
96+
}).rejects.toThrowErrorMatchingInlineSnapshot(
97+
"[Error: Invalid value: invalid. Must be one of: bash, zsh, fish]",
98+
);
12199
});
122100
});
123101

packages/plugin-completions/test/plugin-completions.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe("plugin-completions", () => {
3232
expect(completionsCmd).toBeDefined();
3333
expect(completionsCmd?.flags).toBeDefined();
3434
expect(completionsCmd?.flags?.shell).toBeDefined();
35-
expect(completionsCmd?.parameters).toContain("[shell]");
3635
});
3736

3837
it("should have completion-server command hidden from help", () => {
@@ -65,7 +64,6 @@ describe("plugin-completions", () => {
6564
expect(installCmd).toBeDefined();
6665
expect(installCmd?.flags).toBeDefined();
6766
expect(installCmd?.flags?.shell).toBeDefined();
68-
expect(installCmd?.parameters).toContain("[shell]");
6967

7068
const uninstallCmd = cli._commands.get("completions uninstall");
7169

0 commit comments

Comments
 (0)