Skip to content

Commit 29320b5

Browse files
committed
TDD: Completed repeat-str.test.js with jest test cases
1 parent fae571e commit 29320b5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,37 @@ 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 return the original string when count is 1", () => {
24+
expect(repeatStr("hello", 1)).toEqual("hello");
25+
expect(repeatStr("a", 1)).toEqual("a");
26+
expect(repeatStr("", 1)).toEqual("");
27+
});
2328

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.
33+
test("should return empty string when count is 0", () => {
34+
expect(repeatStr("hello", 0)).toEqual("");
35+
expect(repeatStr("anything", 0)).toEqual("");
36+
expect(repeatStr("", 0)).toEqual("");
37+
});
2838

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+
test("should throw error when count is negative", () => {
44+
expect(() => repeatStr("hello", -1)).toThrow();
45+
expect(() => repeatStr("test", -5)).toThrow();
46+
expect(() => repeatStr("", -3)).toThrow();
47+
});
48+
49+
// Case: Handle positive count:
50+
// Given an empty string `str`and a positive integer `count`,
51+
// When the repeatStr function is called,
52+
// Then it should return an empty string
53+
test("should return empty string when input string is empty", () => {
54+
expect(repeatStr("", 5)).toEqual("");
55+
expect(repeatStr("", 1)).toEqual("");
56+
});

0 commit comments

Comments
 (0)