@@ -9,32 +9,66 @@ import {
9
9
isThrottlingError
10
10
} from "./index" ;
11
11
12
+ const checkForErrorType = (
13
+ isErrorTypeFunc : ( error : Error ) => boolean ,
14
+ errorName : string ,
15
+ errorTypeResult : boolean
16
+ ) => {
17
+ const error = new Error ( ) ;
18
+ error . name = errorName ;
19
+ expect ( isErrorTypeFunc ( error ) ) . toBe ( errorTypeResult ) ;
20
+ } ;
21
+
12
22
describe ( "isClockSkewError" , ( ) => {
13
- for ( const name of Object . keys ( CLOCK_SKEW_ERROR_CODES ) ) {
14
- it ( `should declare errors with the name ${ name } to be throttling errors` , ( ) => {
15
- const error = new Error ( ) ;
16
- error . name = name ;
17
- expect ( isClockSkewError ( error ) ) . toBe ( true ) ;
23
+ CLOCK_SKEW_ERROR_CODES . forEach ( name => {
24
+ it ( `should declare error with the name "${ name } " to be a ClockSkew error` , ( ) => {
25
+ checkForErrorType ( isClockSkewError , name , true ) ;
18
26
} ) ;
27
+ } ) ;
28
+
29
+ while ( true ) {
30
+ const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
31
+ if ( ! CLOCK_SKEW_ERROR_CODES . includes ( name ) ) {
32
+ it ( `should not declare error with the name "${ name } " to be a ClockSkew error` , ( ) => {
33
+ checkForErrorType ( isClockSkewError , name , false ) ;
34
+ } ) ;
35
+ break ;
36
+ }
19
37
}
20
38
} ) ;
21
39
22
40
describe ( "isStillProcessingError" , ( ) => {
23
- for ( const name of Object . keys ( STILL_PROCESSING_ERROR_CODES ) ) {
24
- it ( `should declare errors with the name ${ name } to be throttling errors` , ( ) => {
25
- const error = new Error ( ) ;
26
- error . name = name ;
27
- expect ( isStillProcessingError ( error ) ) . toBe ( true ) ;
41
+ STILL_PROCESSING_ERROR_CODES . forEach ( name => {
42
+ it ( `should declare error with the name "${ name } " to be a StillProcessing error` , ( ) => {
43
+ checkForErrorType ( isStillProcessingError , name , true ) ;
28
44
} ) ;
45
+ } ) ;
46
+
47
+ while ( true ) {
48
+ const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
49
+ if ( ! STILL_PROCESSING_ERROR_CODES . includes ( name ) ) {
50
+ it ( `should not declare error with the name "${ name } " to be a StillProcessing error` , ( ) => {
51
+ checkForErrorType ( isStillProcessingError , name , false ) ;
52
+ } ) ;
53
+ break ;
54
+ }
29
55
}
30
56
} ) ;
31
57
32
58
describe ( "isThrottlingError" , ( ) => {
33
- for ( const name of Object . keys ( THROTTLING_ERROR_CODES ) ) {
34
- it ( `should declare errors with the name ${ name } to be throttling errors` , ( ) => {
35
- const error = new Error ( ) ;
36
- error . name = name ;
37
- expect ( isThrottlingError ( error ) ) . toBe ( true ) ;
59
+ THROTTLING_ERROR_CODES . forEach ( name => {
60
+ it ( `should declare error with the name "${ name } " to be a Throttling error` , ( ) => {
61
+ checkForErrorType ( isThrottlingError , name , true ) ;
38
62
} ) ;
63
+ } ) ;
64
+
65
+ while ( true ) {
66
+ const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
67
+ if ( ! THROTTLING_ERROR_CODES . includes ( name ) ) {
68
+ it ( `should not declare error with the name "${ name } " to be a Throttling error` , ( ) => {
69
+ checkForErrorType ( isThrottlingError , name , false ) ;
70
+ } ) ;
71
+ break ;
72
+ }
39
73
}
40
74
} ) ;
0 commit comments