File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,50 @@ describe("Validation", () => {
98
98
} ) ;
99
99
} ) ;
100
100
101
+ describe ( "validating using custom meta schema" , ( ) => {
102
+ const schema = {
103
+ $ref : "#/definitions/Dataset" ,
104
+ $schema : "http://json-schema.org/draft-04/schema#" ,
105
+ definitions : {
106
+ Dataset : {
107
+ properties : {
108
+ datasetId : {
109
+ pattern : "\\d+" ,
110
+ type : "string" ,
111
+ } ,
112
+ } ,
113
+ required : [ "datasetId" ] ,
114
+ type : "object" ,
115
+ } ,
116
+ } ,
117
+ } ;
118
+ const metaSchema = require ( "ajv/lib/refs/json-schema-draft-04.json" ) ;
119
+
120
+ it . only ( "should return a validation error about meta schema" , ( ) => {
121
+ const errors = validateFormData (
122
+ { datasetId : "some kind of text" } ,
123
+ schema
124
+ ) ;
125
+ expect ( errors . validationErrors . message ) . to . equal (
126
+ 'no schema with key or ref "http://json-schema.org/draft-04/schema#"'
127
+ ) ;
128
+ } ) ;
129
+ it . only ( "should return a validation error about formData" , ( ) => {
130
+ const errors = validateFormData (
131
+ { datasetId : "some kind of text" } ,
132
+ schema ,
133
+ null ,
134
+ null ,
135
+ metaSchema
136
+ ) ;
137
+ expect ( errors . validationErrors ) . to . equal ( null ) ;
138
+ expect ( errors . errors ) . to . have . lengthOf ( 1 ) ;
139
+ expect ( errors . errors [ 0 ] . stack ) . to . equal (
140
+ '.datasetId should match pattern "\\d+"'
141
+ ) ;
142
+ } ) ;
143
+ } ) ;
144
+
101
145
describe ( "Custom validate function" , ( ) => {
102
146
let errors , errorSchema ;
103
147
You can’t perform that action at this time.
0 commit comments