This repository was archived by the owner on Nov 9, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { createChainableTypeChecker } from './common' ;
2
+
1
3
export default function all ( ...propTypes ) {
2
4
if ( propTypes === undefined ) {
3
5
throw new Error ( 'No validations provided' ) ;
@@ -11,13 +13,15 @@ export default function all(...propTypes) {
11
13
throw new Error ( 'No validations provided' ) ;
12
14
}
13
15
14
- return function validate ( props , propName , componentName ) {
16
+ function validate ( props , propName , componentName ) {
15
17
for ( let i = 0 ; i < propTypes . length ; i ++ ) {
16
18
const result = propTypes [ i ] ( props , propName , componentName ) ;
17
19
18
20
if ( result !== undefined && result !== null ) {
19
21
return result ;
20
22
}
21
23
}
22
- } ;
24
+ }
25
+
26
+ return createChainableTypeChecker ( validate ) ;
23
27
}
Original file line number Diff line number Diff line change @@ -56,4 +56,19 @@ describe('all', function() {
56
56
57
57
validators [ 2 ] . should . not . have . been . called ;
58
58
} ) ;
59
+
60
+ it ( 'always fails when prop value is missing and isRequired is used' , function ( ) {
61
+ const missingPropName = 'missing' ;
62
+ const allValidator = all ( ...validators ) . isRequired ;
63
+ const expectedErr = new Error (
64
+ `Required prop '${ missingPropName } ' was not specified in '${ componentName } '.`
65
+ ) ;
66
+
67
+ const result = allValidator ( props , missingPropName , componentName ) ;
68
+ expect ( result . toString ( ) ) . to . equal ( expectedErr . toString ( ) ) ; // cannot compare values, as we got different Error instances here.
69
+
70
+ validators [ 0 ] . should . not . have . been . called ;
71
+ validators [ 1 ] . should . not . have . been . called ;
72
+ validators [ 2 ] . should . not . have . been . called ;
73
+ } ) ;
59
74
} ) ;
You can’t perform that action at this time.
0 commit comments