-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeat.test.js
More file actions
29 lines (25 loc) · 837 Bytes
/
repeat.test.js
File metadata and controls
29 lines (25 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Implement a function repeat
const repeat = require("./repeat");
// case: handle Count of 1:
// When count = 1, return the original string unchanged
test("should return original string when count is 1", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hello");
});
// case: Handle Count of 0:
// When count = 0, return empty string
test("should return an empty string when count is 0", () => {
const str = "world";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});
// case: Negative Count:
// When count < 0, throw an error
test("should throw an error when count is negative", () => {
const str = "test";
const count = -3;
expect(() => repeat(str, count)).toThrow("Count must be non-negative");
});