File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ var valid = require ( '../../lib/validators/type' ) ;
2+
3+ const str = 'Hello world' ;
4+ const obj = { hello : 'world' } ;
5+ const num = 42 ;
6+
7+ const types = {
8+ string : str ,
9+ object : obj ,
10+ number : num
11+ } ;
12+
13+ const typesKeys = Object . keys ( types ) ;
14+
15+ describe ( ' - Type validator' , ( ) => {
16+ it ( 'shall be a function' , ( ) => {
17+ expect ( typeof valid ) . toEqual ( 'function' ) ;
18+ } ) ;
19+
20+
21+ for ( let key in typesKeys ) {
22+ it ( 'shall validate ' + typesKeys [ key ] + ' when no model set' , ( ) => {
23+ expect ( valid ( types [ key ] , { } ) ) . toEqual ( true ) ;
24+ } ) ;
25+ }
26+
27+ for ( let validType in typesKeys ) {
28+ let model = { type : typesKeys [ validType ] } ;
29+ for ( let check in typesKeys ) {
30+ it ( 'shall only validate ' + typesKeys [ validType ] + ' when model set, and ' + typesKeys [ check ] + ' given' , ( ) => {
31+ expect ( valid ( types [ typesKeys [ check ] ] , model ) ) . toEqual ( ( validType === check ) ) ;
32+ } ) ;
33+ }
34+ }
35+
36+ } ) ;
You can’t perform that action at this time.
0 commit comments