Skip to content

Commit 2af6c11

Browse files
author
Pretty Taruvinga
committed
test: add tests for repeatStr
1 parent 715c649 commit 2af6c11

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
function repeatStr() {
2-
return "hellohellohello";
1+
function repeatStr(n, str) {
2+
let result = "";
3+
for (let i = 0; i < n; i++) {
4+
result += str;
5+
}
6+
return result;
37
}
48

59
module.exports = repeatStr;
10+
const repeatStr = require("./repeat-str");
11+
12+
test("repeats a string n times", () => {
13+
expect(repeatStr(3, "hello")).toBe("hellohellohello");
14+
});
15+
16+
test("repeats a different string", () => {
17+
expect(repeatStr(2, "abc")).toBe("abcabc");
18+
});
19+
20+
test("returns empty string when n is 0", () => {
21+
expect(repeatStr(0, "hi")).toBe("");
22+
});

0 commit comments

Comments
 (0)