Skip to content

Commit 220f055

Browse files
Copilotfuxingloh
andcommitted
test: align exit mock with handler guard
Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com>
1 parent e71ddb6 commit 220f055

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/use-agently/src/errors.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("handleCliError", () => {
99
beforeEach(() => {
1010
originalIsTTY = process.stderr.isTTY;
1111
exitSpy = spyOn(process, "exit").mockImplementation((code?: number) => {
12-
throw new Error("exit");
12+
throw new Error("process.exit");
1313
});
1414
errorSpy = spyOn(console, "error").mockImplementation(() => {});
1515
});
@@ -21,23 +21,23 @@ describe("handleCliError", () => {
2121
});
2222

2323
test("prints json error when format is json", () => {
24-
expect(() => handleCliError(new Error("boom"), "json")).toThrow("exit");
24+
expect(() => handleCliError(new Error("boom"), "json")).toThrow("process.exit");
2525
expect(exitSpy).toHaveBeenCalledWith(1);
2626
expect(errorSpy).toHaveBeenCalledWith(JSON.stringify({ error: { message: "boom" } }));
2727
});
2828

2929
test("prints plain text when format is tui and stderr is not a TTY", () => {
3030
Object.defineProperty(process.stderr, "isTTY", { value: false, configurable: true });
3131

32-
expect(() => handleCliError(new Error("oops"), "tui")).toThrow("exit");
32+
expect(() => handleCliError(new Error("oops"), "tui")).toThrow("process.exit");
3333
expect(exitSpy).toHaveBeenCalledWith(1);
3434
expect(errorSpy).toHaveBeenCalledWith("Error: oops");
3535
});
3636

3737
test("prints boxed error when format is tui and stderr is a TTY", () => {
3838
Object.defineProperty(process.stderr, "isTTY", { value: true, configurable: true });
3939

40-
expect(() => handleCliError(new Error("boxed"), "tui")).toThrow("exit");
40+
expect(() => handleCliError(new Error("boxed"), "tui")).toThrow("process.exit");
4141
expect(exitSpy).toHaveBeenCalledWith(1);
4242
const output = errorSpy.mock.calls.map((call) => call[0]).join("");
4343
expect(output).toContain("boxed");

0 commit comments

Comments
 (0)