Skip to content

Commit 07cf09e

Browse files
committed
Added tests for repeatStr function to handle various count scenarios
1 parent b96b949 commit 07cf09e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,30 @@ test("should repeat the string count times", () => {
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
2323

24+
test("should return the original string when count is 1", () => {
25+
expect(repeatStr("hello", 1)).toEqual("hello");
26+
expect(repeatStr("h", 1)).toEqual("h");
27+
expect(repeatStr("", 1)).toEqual("");
28+
});
29+
2430
// Case: Handle count of 0:
2531
// Given a target string `str` and a `count` equal to 0,
2632
// When the repeatStr function is called with these inputs,
2733
// Then it should return an empty string.
2834

35+
test("should return empty string when count is 0", () => {
36+
expect(repeatStr("hello", 0)).toEqual("");
37+
expect(repeatStr("any", 0)).toEqual("");
38+
expect(repeatStr("", 0)).toEqual("");
39+
});
40+
2941
// Case: Handle negative count:
3042
// Given a target string `str` and a negative integer `count`,
3143
// When the repeatStr function is called with these inputs,
3244
// Then it should throw an error, as negative counts are not valid.
45+
46+
test("should throw error when count is negative", () => {
47+
expect(() => repeatStr("hello", -1)).toThrow();
48+
expect(() => repeatStr("test", -5)).toThrow();
49+
expect(() => repeatStr("", -3)).toThrow();
50+
});

0 commit comments

Comments
 (0)