Skip to content

Commit 67d8660

Browse files
committed
Write tests for 2-practice-tdd/repeat-str.test.js
1 parent c953391 commit 67d8660

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,28 @@ 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 if there is no repetition", () => {
25+
const str = "hello";
26+
const count = 1;
27+
const repeatedStr = repeatStr(str, count);
28+
expect(repeatedStr).toEqual("hello");
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.
28-
34+
test("should return an empty string when count is 0", () => {
35+
const str = "hello";
36+
const count = 0;
37+
const repeatedStr = repeatStr(str, count);
38+
expect(repeatedStr).toEqual("");
39+
});
2940
// Case: Handle negative count:
3041
// Given a target string `str` and a negative integer `count`,
3142
// When the repeatStr function is called with these inputs,
3243
// Then it should throw an error, as negative counts are not valid.
44+
test("should throw an error when count is a negative number", () => {
45+
const str = "hello";
46+
const count = -1;
47+
expect(() => repeatStr(str, count)).toThrowError();
48+
});

0 commit comments

Comments
 (0)