Skip to content

Commit 9776061

Browse files
authored
Add tests for repeatStr function edge cases
1 parent 37f4601 commit 9776061

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,27 @@ 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+
28+
2429
// Case: Handle count of 0:
2530
// Given a target string `str` and a `count` equal to 0,
2631
// When the repeatStr function is called with these inputs,
2732
// Then it should return an empty string.
2833

34+
test("should return an empty string when count is 0", () => {
35+
expect(repeatStr("hello", 0)).toEqual("");
36+
});
37+
38+
2939
// Case: Handle negative count:
3040
// Given a target string `str` and a negative integer `count`,
3141
// When the repeatStr function is called with these inputs,
3242
// Then it should throw an error, as negative counts are not valid.
43+
44+
45+
test("should throw an error when count is negative", () => {
46+
expect(() => repeatStr("hello", -1)).toThrow("Count cannot be negative");
47+
});

0 commit comments

Comments
 (0)