Skip to content

Commit e28e199

Browse files
update tests for repeat function to handle non-string input and array count
1 parent 9c86871 commit e28e199

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ test("should return an empty string", ()=>{
4040
expect(repeatedStr).toEqual("");
4141
})
4242

43+
// case: Handle str not a string:
44+
// Given a number and a count equal to 2,
45+
// When the repeat function is called with these inputs,
46+
// Then it should return an error message.
47+
48+
test("should return an error message", ()=>{
49+
const str = 5;
50+
const count = 5;
51+
const repeatedStr = repeat(str, count);
52+
expect(repeatedStr).toEqual("Error: str must be a string");
53+
})
54+
4355
// case: Handle Count of Undefined:
4456
// Given a target string str and a count equal to Undefined,
4557
// When the repeat function is called with these inputs,
@@ -52,6 +64,18 @@ test("should return an error message", ()=>{
5264
expect(repeatedStr).toEqual("Error : count must be a positive integer");
5365
})
5466

67+
// case: Handle Count of array:
68+
// Given a target string str and a count equal to [],
69+
// When the repeat function is called with these inputs,
70+
// Then it should return an error message.
71+
72+
test("should return an error message", ()=>{
73+
const str = "hello";
74+
const count = [];
75+
const repeatedStr = repeat(str, count);
76+
expect(repeatedStr).toEqual("Error : count must be a positive integer");
77+
})
78+
5579
// case: Negative Count:
5680
// Given a target string str and a negative integer count,
5781
// When the repeat function is called with these inputs,

0 commit comments

Comments
 (0)