File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ export default function validateFormData(
163
163
schema ,
164
164
customValidate ,
165
165
transformErrors ,
166
- additionalMetaSchemas
166
+ additionalMetaSchemas = [ ]
167
167
) {
168
168
// add more schemas to validate against
169
169
if (
Original file line number Diff line number Diff line change 9
9
createComponent ,
10
10
createFormComponent ,
11
11
createSandbox ,
12
+ setProps ,
12
13
} from "./test_utils" ;
13
14
14
15
describe ( "Form" , ( ) => {
@@ -1977,4 +1978,42 @@ describe("Form", () => {
1977
1978
expect ( node . getAttribute ( "novalidate" ) ) . not . to . be . null ;
1978
1979
} ) ;
1979
1980
} ) ;
1981
+
1982
+ describe ( "Meta schema updates" , ( ) => {
1983
+ it ( "Should update allowed meta schemas when additionalMetaSchemas is changed" , ( ) => {
1984
+ const formProps = {
1985
+ liveValidate : true ,
1986
+ schema : {
1987
+ $schema : "http://json-schema.org/draft-04/schema#" ,
1988
+ type : "string" ,
1989
+ minLength : 8 ,
1990
+ pattern : "d+" ,
1991
+ } ,
1992
+ formData : "short" ,
1993
+ additionalMetaSchemas : [ ] ,
1994
+ } ;
1995
+
1996
+ const { comp } = createFormComponent ( formProps ) ;
1997
+
1998
+ expect ( comp . state . errorSchema ) . eql ( { } ) ;
1999
+
2000
+ setProps ( comp , {
2001
+ ...formProps ,
2002
+ additionalMetaSchemas : [
2003
+ require ( "ajv/lib/refs/json-schema-draft-04.json" ) ,
2004
+ ] ,
2005
+ } ) ;
2006
+
2007
+ expect ( comp . state . errorSchema ) . eql ( {
2008
+ __errors : [
2009
+ "should NOT be shorter than 8 characters" ,
2010
+ 'should match pattern "d+"' ,
2011
+ ] ,
2012
+ } ) ;
2013
+
2014
+ setProps ( comp , formProps ) ;
2015
+
2016
+ expect ( comp . state . errorSchema ) . eql ( { } ) ;
2017
+ } ) ;
2018
+ } ) ;
1980
2019
} ) ;
You can’t perform that action at this time.
0 commit comments