Skip to content

Commit 8012dd6

Browse files
committed
update - repeat str test
1 parent 1973ce9 commit 8012dd6

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

‎practice-tdd/repeat-str.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function repeatStr(str, count) {
22
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
33
// The goal is to re-implement that function, not to use it.
44
if (count < 0) {
5-
return "negative counts are not valid";
5+
throw new Error("should throw an error,as negative counts are not valid");
66
}
77
let result = "";
88
for (let i = 0; i < count; i++) {

‎practice-tdd/repeat-str.test.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ test("should return an empty string when the string is empty and count is 0", ()
5757
// Given a target string `str` and a negative integer `count`,
5858
// When the repeatStr function is called with these inputs,
5959
// Then it should throw an error, as negative counts are not valid.
60-
test("should return an error, as negative counts are not valid", () => {
60+
test("should throw an error, as negative counts are not valid", () => {
6161
const str = "hello";
6262
const count = -1;
63-
const repeatedStr = repeatStr(str, count);
64-
expect(repeatedStr).toEqual("negative counts are not valid");
63+
expect(() => repeatStr(str, count)).toThrow();
6564
});

0 commit comments

Comments
 (0)