Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Commit b16be61

Browse files
authored
Merge pull request #391 from CodeYourFuture/fix-reverse-log-test
change assertion to nthCalledWith
2 parents 61e6c6c + 5fcac12 commit b16be61

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

mandatory/2-function-creation.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ describe("printOddNumbers", () => {
9090
const consoleLogSpy = jest.spyOn(console, "log");
9191

9292
printOddNumbers(10);
93-
expect(consoleLogSpy).toBeCalledWith(1);
94-
expect(consoleLogSpy).toBeCalledWith(3);
95-
expect(consoleLogSpy).toBeCalledWith(5);
96-
expect(consoleLogSpy).toBeCalledWith(7);
97-
expect(consoleLogSpy).toBeCalledWith(9);
93+
expect(consoleLogSpy).toHaveBeenNthCalledWith(1,1);
94+
expect(consoleLogSpy).toHaveBeenNthCalledWith(2,3);
95+
expect(consoleLogSpy).toHaveBeenNthCalledWith(3,5);
96+
expect(consoleLogSpy).toHaveBeenNthCalledWith(4,7);
97+
expect(consoleLogSpy).toHaveBeenNthCalledWith(5,9);
9898

9999
consoleLogSpy.mockRestore();
100100
});
@@ -140,13 +140,14 @@ describe("countReverse", () => {
140140
test("countReverse function logs values from 7 to 1", () => {
141141
const consoleLogSpy = jest.spyOn(console, "log");
142142

143-
expect(consoleLogSpy).toBeCalledWith(7);
144-
expect(consoleLogSpy).toBeCalledWith(6);
145-
expect(consoleLogSpy).toBeCalledWith(5);
146-
expect(consoleLogSpy).toBeCalledWith(4);
147-
expect(consoleLogSpy).toBeCalledWith(3);
148-
expect(consoleLogSpy).toBeCalledWith(2);
149-
expect(consoleLogSpy).toBeCalledWith(1);
143+
countReverse(7);
144+
expect(consoleLogSpy).toHaveBeenNthCalledWith(1,7);
145+
expect(consoleLogSpy).toHaveBeenNthCalledWith(2,6);
146+
expect(consoleLogSpy).toHaveBeenNthCalledWith(3,5);
147+
expect(consoleLogSpy).toHaveBeenNthCalledWith(4,4);
148+
expect(consoleLogSpy).toHaveBeenNthCalledWith(5,3);
149+
expect(consoleLogSpy).toHaveBeenNthCalledWith(6,2);
150+
expect(consoleLogSpy).toHaveBeenNthCalledWith(7,1);
150151

151152
consoleLogSpy.mockRestore();
152153
});

0 commit comments

Comments
 (0)