Skip to content

Commit 9d4dd77

Browse files
committed
repeat-str jest
1 parent 050f3c5 commit 9d4dd77

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const repeatStr = require("./repeat-str");
44
// When the repeatStr function is called with these inputs,
55
// Then it should:
66

7+
78
// Case: handle multiple repetitions:
89
// Given a target string `str` and a positive integer `count` greater than 1,
910
// When the repeatStr function is called with these inputs,
@@ -16,17 +17,40 @@ test("should repeat the string count times", () => {
1617
expect(repeatedStr).toEqual("hellohellohello");
1718
});
1819

20+
1921
// Case: handle count of 1:
2022
// Given a target string `str` and a `count` equal to 1,
2123
// When the repeatStr function is called with these inputs,
2224
// Then it should return the original `str` without repetition.
2325

26+
test("should return the original string when count is 1", () => {
27+
const str = "world";
28+
const count = 1;
29+
const repeatedStr = repeatStr(str, count);
30+
expect(repeatedStr).toEqual("world");
31+
});
32+
33+
2434
// Case: Handle count of 0:
2535
// Given a target string `str` and a `count` equal to 0,
2636
// When the repeatStr function is called with these inputs,
2737
// Then it should return an empty string.
2838

39+
test("should return an empty string when count is 0", () => {
40+
const str = "test";
41+
const count = 0;
42+
const repeatedStr = repeatStr(str, count);
43+
expect(repeatedStr).toEqual("");
44+
});
45+
46+
2947
// Case: Handle negative count:
3048
// Given a target string `str` and a negative integer `count`,
3149
// When the repeatStr function is called with these inputs,
3250
// Then it should throw an error, as negative counts are not valid.
51+
52+
test("should throw an error when count is negative", () => {
53+
const str = "error";
54+
const count = -2;
55+
expect(() => repeatStr(str, count)).toThrow();
56+
});

0 commit comments

Comments
 (0)