Skip to content

Commit 4230028

Browse files
committed
fix: update mock declarations and test expectations
1 parent fc59c49 commit 4230028

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

cli/__tests__/build.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ jest.mock("../utils", () => ({
1818
}));
1919
jest.mock("../../build");
2020

21+
// Mock fs and path modules
22+
jest.mock("fs");
23+
jest.mock("path");
24+
2125
// Create mock functions for fs and path
2226
const mockExistsSync = jest.fn();
2327
const mockResolve = jest.fn();
2428

25-
// Mock fs and path modules
26-
jest.mock("fs", () => ({
27-
existsSync: mockExistsSync,
28-
}));
29-
30-
jest.mock("path", () => ({
31-
resolve: mockResolve,
32-
}));
29+
// Override module exports with mocks
30+
jest.mocked(require("fs")).existsSync = mockExistsSync;
31+
jest.mocked(require("path")).resolve = mockResolve;
3332

3433
/**
3534
* Test suite for the build command

cli/__tests__/list.test.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ jest.mock("../utils", () => ({
1818
}));
1919
jest.mock("../../list");
2020

21+
// Mock fs and path modules
22+
jest.mock("fs");
23+
jest.mock("path");
24+
2125
// Create mock functions for fs and path
2226
const mockExistsSync = jest.fn();
2327
const mockResolve = jest.fn();
2428

25-
// Mock fs and path modules
26-
jest.mock("fs", () => ({
27-
existsSync: mockExistsSync,
28-
}));
29-
30-
jest.mock("path", () => ({
31-
resolve: mockResolve,
32-
}));
29+
// Override module exports with mocks
30+
jest.mocked(require("fs")).existsSync = mockExistsSync;
31+
jest.mocked(require("path")).resolve = mockResolve;
3332

3433
/**
3534
* Test suite for the list command
@@ -39,15 +38,15 @@ jest.mock("path", () => ({
3938
describe("cmdList", () => {
4039
// Store original console.log
4140
const originalConsoleLog = console.log;
42-
41+
4342
beforeEach(() => {
4443
// Reset all mocks before each test
4544
jest.clearAllMocks();
46-
45+
4746
// Setup default mock implementations
4847
mockExistsSync.mockReturnValue(true);
4948
mockResolve.mockImplementation((...args) => args.join("/"));
50-
49+
5150
// Mock console.log
5251
console.log = jest.fn();
5352
});
@@ -68,10 +67,13 @@ describe("cmdList", () => {
6867
*/
6968
test("displays help message when --help flag is used", () => {
7069
const mockPrintAndExit = utils.printAndExit as jest.MockedFunction<typeof utils.printAndExit>;
71-
70+
7271
cmdList(["--help"]);
73-
74-
expect(mockPrintAndExit).toHaveBeenCalledWith(expect.stringContaining("Usage"), 0);
72+
73+
expect(mockPrintAndExit).toHaveBeenCalledWith(
74+
expect.stringContaining("Usage"),
75+
0
76+
);
7577
});
7678

7779
/**
@@ -81,10 +83,12 @@ describe("cmdList", () => {
8183
test("validates out directory exists when specified", () => {
8284
const mockPrintAndExit = utils.printAndExit as jest.MockedFunction<typeof utils.printAndExit>;
8385
mockExistsSync.mockReturnValue(false);
84-
86+
8587
cmdList(["--out-dir", "/non/existent/dir"]);
86-
87-
expect(mockPrintAndExit).toHaveBeenCalledWith(expect.stringContaining("/non/existent/dir"));
88+
89+
expect(mockPrintAndExit).toHaveBeenCalledWith(
90+
expect.stringContaining("/non/existent/dir")
91+
);
8892
});
8993

9094
/**
@@ -94,12 +98,10 @@ describe("cmdList", () => {
9498
test("calls list with correct parameters", () => {
9599
const mockList = list as jest.MockedFunction<typeof list>;
96100
const args = ["--out-dir", "/output/dir"];
97-
101+
98102
cmdList(args);
99-
100-
expect(mockList).toHaveBeenCalledWith({
101-
outDir: "/output/dir",
102-
});
103+
104+
expect(mockList).toHaveBeenCalledWith("/output/dir");
103105
});
104106

105107
/**
@@ -108,10 +110,10 @@ describe("cmdList", () => {
108110
*/
109111
test("calls list with undefined when no out-dir specified", () => {
110112
const mockList = list as jest.MockedFunction<typeof list>;
111-
113+
112114
cmdList([]);
113-
114-
expect(mockList).toHaveBeenCalledWith({});
115+
116+
expect(mockList).toHaveBeenCalledWith(undefined);
115117
});
116118

117119
/**
@@ -120,9 +122,11 @@ describe("cmdList", () => {
120122
*/
121123
test("handles unknown options gracefully", () => {
122124
const mockPrintAndExit = utils.printAndExit as jest.MockedFunction<typeof utils.printAndExit>;
123-
125+
124126
cmdList(["--unknown-flag"]);
125-
126-
expect(mockPrintAndExit).toHaveBeenCalledWith(expect.stringContaining("--unknown-flag"));
127+
128+
expect(mockPrintAndExit).toHaveBeenCalledWith(
129+
expect.stringContaining("--unknown-flag")
130+
);
127131
});
128132
});

0 commit comments

Comments
 (0)