Skip to content

Commit 4c99807

Browse files
committed
Test: add repeat.test.js to verify repeat function
- Added tests for repeat() covering: • repeating a string multiple times • returning empty string when count is 0 • throwing error when count is negative - Cleaned up unused code to follow best practices
1 parent cbb4e8d commit 4c99807

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const repeat = require("./repeat");
2+
3+
describe("repeat function tests", () => {
4+
5+
test("repeats string given number of times", () => {
6+
expect(repeat("hi", 3)).toBe("hihihi");
7+
expect(repeat("abc", 2)).toBe("abcabc");
8+
});
9+
10+
test("returns empty string when count is 0", () => {
11+
expect(repeat("hello", 0)).toBe("");
12+
});
13+
14+
test("throws error if count is negative", () => {
15+
expect(() => repeat("hi", -1)).toThrow("Count must be non-negative");
16+
});
17+
18+
});

0 commit comments

Comments
 (0)