Skip to content

Commit b548ddb

Browse files
committed
feat: update negative count error message in repeatStr
- Added an emoji to the error string. - Included try/catch blocks in tests to verify manual error capturing. - Updated Jest assertions to match the new error format.
1 parent 4c0130e commit b548ddb

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,8 +1,8 @@
11
function repeatStr(str, count) {
22
if (count < 0) {
3-
throw new Error("count cannot be negative");
3+
throw new Error("count cannot be negative 😭");
44
}
5-
5+
66
let result = "";
77
for (let i = 0; i < count; i++) {
88
result = result + str;
@@ -12,3 +12,20 @@ function repeatStr(str, count) {
1212

1313
module.exports = repeatStr;
1414

15+
16+
// Case: Manual inspection of the Error object
17+
// We use try/catch to log the error message to the console
18+
// to verify it's working as expected without breaking the test suite.
19+
test("Should log the specific error message to the console", () => {
20+
try {
21+
repeatStr("hi", -3);
22+
} catch (error) {
23+
console.log("Verified Error Message ->", error.message);
24+
25+
// Check if the message is exactly what we defined
26+
expect(error.message).toBe("count cannot be negative 😭");
27+
}
28+
29+
// Also verify that it actually throws using Jest's built-in matcher
30+
expect(() => repeatStr("hi", -3)).toThrow();
31+
});

0 commit comments

Comments
 (0)