Skip to content

Commit 164b190

Browse files
authored
Add tests for repeatStr function edge cases
1 parent f9bca95 commit 164b190

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@ 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+
});
27+
2428
// Case: Handle count of 0:
2529
// Given a target string `str` and a `count` equal to 0,
2630
// When the repeatStr function is called with these inputs,
2731
// Then it should return an empty string.
2832

33+
test("should return an empty string when count is 0", () => {
34+
expect(repeatStr("hello", 0)).toEqual("");
35+
});
36+
2937
// Case: Handle negative count:
3038
// Given a target string `str` and a negative integer `count`,
3139
// When the repeatStr function is called with these inputs,
3240
// Then it should throw an error, as negative counts are not valid.
41+
42+
43+
test("should throw an error when count is negative", () => {
44+
expect(() => repeatStr("hello", -1)).toThrow();
45+
});

0 commit comments

Comments
 (0)