Skip to content

Commit 015ca08

Browse files
committed
Improve tests
1 parent dfc788b commit 015ca08

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/git.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("getRangesForDiff", () => {
4848

4949
describe("getDiffForFile", () => {
5050
it("should get the staged diff of a file", () => {
51-
mockedChildProcess.execSync.mockReturnValue(Buffer.from(hunks));
51+
mockedChildProcess.execSync.mockReturnValueOnce(Buffer.from(hunks));
5252
process.env.ESLINT_PLUGIN_DIFF_COMMIT = "1234567";
5353

5454
const diffFromFile = getDiffForFile("./mockfile.js", true);
@@ -70,6 +70,7 @@ describe("getDiffForFile", () => {
7070
jest.mock("child_process").resetAllMocks();
7171
mockedChildProcess.execSync.mockReturnValueOnce(Buffer.from(hunks));
7272

73+
expect(mockedChildProcess.execSync).toHaveBeenCalledTimes(0);
7374
const diffFromFileA = getDiffForFile("./mockfileCache.js");
7475
const diffFromFileB = getDiffForFile("./mockfileCache.js");
7576
expect(mockedChildProcess.execSync).toHaveBeenCalledTimes(1);
@@ -84,14 +85,16 @@ describe("getDiffForFile", () => {
8485
describe("getDiffFileList", () => {
8586
it("should get the list of staged files", () => {
8687
jest.mock("child_process").resetAllMocks();
87-
mockedChildProcess.execSync.mockReturnValue(Buffer.from(diffFileList));
88+
mockedChildProcess.execSync.mockReturnValueOnce(Buffer.from(diffFileList));
8889
const staged = false;
89-
const fileList = getDiffFileList(staged);
90+
const fileListA = getDiffFileList(staged);
91+
const fileListB = getDiffFileList(staged);
9092

9193
expect(mockedChildProcess.execSync).toHaveBeenCalled();
92-
expect(fileList).toEqual(
94+
expect(fileListA).toEqual(
9395
["file1", "file2", "file3"].map((p) => path.resolve(p))
9496
);
97+
expect(fileListA).toEqual(fileListB);
9598
});
9699
});
97100

0 commit comments

Comments
 (0)