Skip to content

Commit fd9f87c

Browse files
committed
Cover hasCleanIndex
1 parent 015ca08 commit fd9f87c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/git.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getDiffForFile,
77
getGitFileList,
88
getRangesForDiff,
9+
hasCleanIndex,
910
} from "./git";
1011
import {
1112
diffFileList,
@@ -82,6 +83,24 @@ describe("getDiffForFile", () => {
8283
});
8384
});
8485

86+
describe("hasCleanIndex", () => {
87+
it("returns false instead of throwing", () => {
88+
jest.mock("child_process").resetAllMocks();
89+
mockedChildProcess.execSync.mockImplementationOnce(() => {
90+
throw Error("mocked error");
91+
});
92+
expect(hasCleanIndex("")).toEqual(false);
93+
expect(mockedChildProcess.execSync).toHaveBeenCalled();
94+
});
95+
96+
it("returns true otherwise", () => {
97+
jest.mock("child_process").resetAllMocks();
98+
mockedChildProcess.execSync.mockReturnValue(Buffer.from(""));
99+
expect(hasCleanIndex("")).toEqual(true);
100+
expect(mockedChildProcess.execSync).toHaveBeenCalled();
101+
});
102+
});
103+
85104
describe("getDiffFileList", () => {
86105
it("should get the list of staged files", () => {
87106
jest.mock("child_process").resetAllMocks();

0 commit comments

Comments
 (0)