Skip to content

Commit 3be91c2

Browse files
committed
resolve invalide input to throw a new error insted a return a massage
1 parent 034d8f8 commit 3be91c2

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
function repeat(myString, repeatNumber) {
2-
if (repeatNumber < 0) return "Invalid Input must be a positive number";
3-
//if (repeatNumber < 0) throw new Error("Repeat count must be a positive number");
2+
if (repeatNumber < 0) throw new Error("Repeat count must be a positive number");
43
// if I use this instead return how I can test it with jest??
54
return myString.repeat(repeatNumber);
65
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ test("should return empty when the count is 0", () => {
4646
test("should return empty when the count is negative", () => {
4747
const str = "CYF";
4848
const count = -2;
49-
const repeatedStr = repeat(str, count);
50-
expect(repeatedStr).toEqual("Invalid Input must be a positive number");
49+
50+
expect(() => repeat(str,count)).toThrow("Repeat count must be a positive number");
5151
});
5252
test("should repeat the string five times when the count is 5", () => {
5353
const str = "CYF";

0 commit comments

Comments
 (0)