Skip to content

Commit d16ab8a

Browse files
committed
edit test file and change difficulty level to 4 which is medium
1 parent 27454cd commit d16ab8a

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,7 @@
27772777
"uuid": "de1c75f2-2461-4347-b5ca-b3cfaafe4d79",
27782778
"practices": [],
27792779
"prerequisites": [],
2780-
"difficulty": 1
2780+
"difficulty": 4
27812781
}
27822782
]
27832783
},

exercises/practice/error-handling/error-handling.spec.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,30 @@ import { describe, expect, test, xtest } from '@jest/globals';
22
import { processString } from './error-handling';
33

44
describe('Error Handling', () => {
5-
test('throws TypeError if input is not a string', () => {
5+
test('never throws a generic Error for any invalid input', () => {
6+
const invalidInputs = [
7+
42, // TypeError
8+
'short', // RangeError (too short)
9+
'a'.repeat(101), // RangeError (too long)
10+
'12345test6789text', // SyntaxError (mixed)
11+
];
12+
13+
for (const input of invalidInputs) {
14+
let error;
15+
16+
try {
17+
processString(input);
18+
} catch (err) {
19+
error = err;
20+
}
21+
22+
expect(error).toBeInstanceOf(Error);
23+
expect(error.constructor).not.toBe(Error);
24+
expect(error.message).toEqual(expect.stringMatching(/.+/));
25+
}
26+
});
27+
28+
xtest('throws TypeError if input is not a string', () => {
629
expect(() => processString(42)).toThrow(
730
expect.objectContaining({
831
name: 'TypeError',
@@ -11,10 +34,6 @@ describe('Error Handling', () => {
1134
);
1235
});
1336

14-
xtest('returns null if string is empty', () => {
15-
expect(processString('')).toBeNull();
16-
});
17-
1837
xtest('throws error if input is too short', () => {
1938
expect(() => processString('short')).toThrow(
2039
expect.objectContaining({
@@ -43,30 +62,11 @@ describe('Error Handling', () => {
4362
);
4463
});
4564

46-
xtest('returns uppercase string if input is valid', () => {
47-
expect(processString('hellotherefriend')).toBe('HELLOTHEREFRIEND');
65+
xtest('returns null if string is empty', () => {
66+
expect(processString('')).toBeNull();
4867
});
4968

50-
xtest('never throws a generic Error for any invalid input', () => {
51-
const invalidInputs = [
52-
42, // TypeError
53-
'short', // RangeError (too short)
54-
'a'.repeat(101), // RangeError (too long)
55-
'12345test6789text', // SyntaxError (mixed)
56-
];
57-
58-
for (const input of invalidInputs) {
59-
let error;
60-
61-
try {
62-
processString(input);
63-
} catch (err) {
64-
error = err;
65-
}
66-
67-
expect(error).toBeInstanceOf(Error);
68-
expect(error.constructor).not.toBe(Error);
69-
expect(error.message).toEqual(expect.stringMatching(/.+/));
70-
}
69+
xtest('returns uppercase string if input is valid', () => {
70+
expect(processString('hellotherefriend')).toBe('HELLOTHEREFRIEND');
7171
});
7272
});

0 commit comments

Comments
 (0)