@@ -2,7 +2,30 @@ import { describe, expect, test, xtest } from '@jest/globals';
22import { processString } from './error-handling' ;
33
44describe ( '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