Skip to content

Commit a258022

Browse files
committed
added jest test cases to check the function
1 parent 50bce35 commit a258022

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,33 @@ test("should repeat the string count times", () => {
2020
// Given a target string `str` and a `count` equal to 1,
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
23+
test("should repeat the string count times", () => {
24+
const str = "what";
25+
const count = 1;
26+
const repeatedStr = repeatStr(str, count);
27+
expect(repeatedStr).toEqual("what");
28+
});
2329

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 an empty string", () => {
36+
const str = "hello";
37+
const count = 0;
38+
const repeatedStr = repeatStr(str, count);
39+
expect(repeatedStr).toEqual("");
40+
});
41+
2942
// Case: Handle negative count:
3043
// Given a target string `str` and a negative integer `count`,
3144
// When the repeatStr function is called with these inputs,
3245
// Then it should throw an error, as negative counts are not valid.
46+
test("should throw an error message", () => {
47+
const str = "hello";
48+
const count = -3;
49+
expect(() => {
50+
repeatStr(str, count);
51+
}).toThrow();
52+
});

0 commit comments

Comments
 (0)