This repository was archived by the owner on May 7, 2024. It is now read-only.
File tree 2 files changed +78
-1
lines changed
2 files changed +78
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ const optionsSchema = {
20
20
} ,
21
21
required : [
22
22
'environmentModulePath'
23
- ]
23
+ ] ,
24
+ additionalProperties : false
24
25
} ;
25
26
26
27
class PathSupportingArrayLoader extends TwingLoaderArray {
Original file line number Diff line number Diff line change @@ -49,5 +49,81 @@ tape('loader', (test: Test) => {
49
49
test . end ( ) ;
50
50
} ) ;
51
51
52
+ test . test ( 'provides options validation' , ( test ) => {
53
+ type ValidationError = {
54
+ dataPath : string ,
55
+ keyword : string ,
56
+ message : string
57
+ } ;
58
+
59
+ type Fixture = {
60
+ options : any ,
61
+ expectation : ValidationError
62
+ } ;
63
+
64
+ let fixtures : Fixture [ ] = [
65
+ {
66
+ options : { } ,
67
+ expectation : {
68
+ dataPath : '' ,
69
+ keyword : 'required' ,
70
+ message : 'should have required property \'environmentModulePath\''
71
+ }
72
+ } ,
73
+ {
74
+ options : {
75
+ environmentModulePath : { }
76
+ } ,
77
+ expectation : {
78
+ dataPath : '.environmentModulePath' ,
79
+ keyword : 'type' ,
80
+ message : 'should be string'
81
+ }
82
+ } ,
83
+ {
84
+ options : {
85
+ environmentModulePath : '' ,
86
+ renderContext : ''
87
+ } ,
88
+ expectation : {
89
+ dataPath : '.renderContext' ,
90
+ keyword : 'type' ,
91
+ message : 'should be object'
92
+ }
93
+ } ,
94
+ {
95
+ options : {
96
+ environmentModulePath : '' ,
97
+ foo : ''
98
+ } ,
99
+ expectation : {
100
+ dataPath : '' ,
101
+ keyword : 'additionalProperties' ,
102
+ message : 'should NOT have additional properties'
103
+ }
104
+ }
105
+ ] ;
106
+
107
+ for ( let fixture of fixtures ) {
108
+ let errors : ValidationError [ ] ;
109
+
110
+ try {
111
+ loader . bind ( {
112
+ query : fixture . options
113
+ } ) ( ) ;
114
+
115
+ errors = [ ] ;
116
+ } catch ( e ) {
117
+ errors = e . errors ;
118
+ }
119
+
120
+ test . same ( errors [ 0 ] . dataPath , fixture . expectation . dataPath ) ;
121
+ test . same ( errors [ 0 ] . keyword , fixture . expectation . keyword ) ;
122
+ test . same ( errors [ 0 ] . message , fixture . expectation . message ) ;
123
+ }
124
+
125
+ test . end ( ) ;
126
+ } ) ;
127
+
52
128
test . end ( ) ;
53
129
} ) ;
You can’t perform that action at this time.
0 commit comments