Skip to content

Commit 86215d3

Browse files
Adding jest test case for throw an error for negative count
1 parent ac6fa53 commit 86215d3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ test("should return the original string when count is 1", () => {
2727
// Given a target string `str` and a `count` equal to 0,
2828
// When the repeatStr function is called with these inputs,
2929
// Then it should return an empty string.
30-
30+
test("should return empty string when count is 0", () => {
31+
expect(repeatStr("hello", 0)).toEqual("");
32+
})
3133
// Case: Handle negative count:
3234
// Given a target string `str` and a negative integer `count`,
3335
// When the repeatStr function is called with these inputs,
3436
// Then it should throw an error, as negative counts are not valid.
37+
test("should throw an error for negative count", () => {
38+
expect(() => repeatStr("hello", -1)).toThrow("Count cannot be negative");
39+
});

0 commit comments

Comments
 (0)