File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,10 @@ function isValid(data, model) {
1111 return true ;
1212 }
1313
14- if ( ( typeof ( data ) ) . toUpperCase ( ) === model . type . toUpperCase ( ) ) {
14+ if ( ( typeof data ) . toUpperCase ( ) === model . type . toUpperCase ( ) ) {
1515 return true ;
16+ } else if ( model . type . toUpperCase ( ) === 'ARRAY' ) {
17+ return Array . isArray ( data ) ;
1618 }
1719
1820 return false ;
Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ const str = 'Hello world';
44const obj = { hello : 'world' } ;
55const num = 42 ;
66const bool = true ;
7+ const arr = [ 1 , 2 , 3 ] ;
78
89const types = {
910 string : str ,
1011 object : obj ,
1112 number : num ,
12- boolean : bool
13+ boolean : bool ,
14+ array : arr
1315} ;
1416const typesKeys = Object . keys ( types ) ;
1517
@@ -28,7 +30,14 @@ describe(' - Type validator', () => {
2830 let model = { type : typesKeys [ validType ] } ;
2931 for ( let check in typesKeys ) {
3032 it ( 'shall only validate ' + typesKeys [ validType ] + ' when model set, and ' + typesKeys [ check ] + ' given' , ( ) => {
31- expect ( valid ( types [ typesKeys [ check ] ] , model ) ) . toEqual ( ( validType === check ) ) ;
33+ let shallBeValid = ( validType === check ) ;
34+
35+ // Since arrays are also valid object types, shall do some special check
36+ if ( typesKeys [ validType ] === 'object' && typesKeys [ check ] === 'array' ) {
37+ shallBeValid = true ;
38+ }
39+
40+ expect ( valid ( types [ typesKeys [ check ] ] , model ) ) . toEqual ( shallBeValid ) ;
3241 } ) ;
3342 }
3443 }
You can’t perform that action at this time.
0 commit comments