@@ -676,38 +676,12 @@ describe("Validation", () => {
676
676
} ) ;
677
677
} ) ;
678
678
describe ( "Custom meta schema" , ( ) => {
679
- let sandboxErr ;
680
679
let onSubmit ;
681
680
let onError ;
682
- let compWithMeta , nodeWithMeta , compWithoutMeta , nodeWithoutMeta ;
683
-
684
- beforeEach ( ( ) => {
685
- sandboxErr = sinon . sandbox . create ( ) ;
686
- onSubmit = sandboxErr . spy ( ) ;
687
- onError = sandboxErr . spy ( ) ;
688
- const withMetaSchema = createFormComponent ( {
689
- schema,
690
- formData,
691
- metaSchema : require ( "ajv/lib/refs/json-schema-draft-04.json" ) ,
692
- onSubmit,
693
- onError,
694
- } ) ;
695
-
696
- compWithMeta = withMetaSchema . comp ;
697
- nodeWithMeta = withMetaSchema . node ;
698
- const withoutMetaSchema = createFormComponent ( {
699
- schema,
700
- formData,
701
- onSubmit,
702
- onError,
703
- } ) ;
704
- compWithoutMeta = withoutMetaSchema . comp ;
705
- nodeWithoutMeta = withoutMetaSchema . node ;
706
- } ) ;
707
-
708
- afterEach ( ( ) => {
709
- sandboxErr . restore ( ) ;
710
- } ) ;
681
+ let comp , node ;
682
+ const formData = {
683
+ datasetId : "no err" ,
684
+ } ;
711
685
712
686
const schema = {
713
687
$ref : "#/definitions/Dataset" ,
@@ -725,28 +699,31 @@ describe("Validation", () => {
725
699
} ,
726
700
} ,
727
701
} ;
728
- const formData = {
729
- datasetId : "no err" ,
730
- } ;
731
702
732
- it . only ( "asd" , ( ) => {
733
- Simulate . submit ( nodeWithoutMeta ) ;
734
- expect (
735
- nodeWithoutMeta . querySelectorAll ( ".errors li" )
736
- ) . to . have . length . of ( 0 ) ;
737
- expect ( compWithoutMeta . state . errors ) . to . have . lengthOf ( 0 ) ;
738
- } ) ;
739
- it . only ( "query select" , ( ) => {
740
- Simulate . submit ( nodeWithMeta ) ;
741
- expect ( nodeWithMeta . querySelectorAll ( ".errors li" ) ) . to . have . length . of (
742
- 1
743
- ) ;
744
- expect ( compWithMeta . state . errors [ 0 ] . message ) . eql (
745
- `should match pattern "\\d+"`
746
- ) ;
703
+ beforeEach ( ( ) => {
704
+ onSubmit = sandbox . spy ( ) ;
705
+ onError = sandbox . spy ( ) ;
706
+ const withMetaSchema = createFormComponent ( {
707
+ schema,
708
+ formData,
709
+ liveValidate : true ,
710
+ metaSchema : require ( "ajv/lib/refs/json-schema-draft-04.json" ) ,
711
+ onSubmit,
712
+ onError,
713
+ } ) ;
714
+ comp = withMetaSchema . comp ;
715
+ node = withMetaSchema . node ;
747
716
} ) ;
748
- it . only ( "dff" , ( ) => {
749
- // expect(compWithoutMeta.state.errors).to.have.length.of(0);
717
+
718
+ it ( "should be used to validate schema" , ( ) => {
719
+ expect ( node . querySelectorAll ( ".errors li" ) ) . to . have . length . of ( 1 ) ;
720
+ expect ( comp . state . errors ) . to . have . lengthOf ( 1 ) ;
721
+ expect ( comp . state . errors [ 0 ] . message ) . eql ( `should match pattern "\\d+"` ) ;
722
+ Simulate . change ( node . querySelector ( "input" ) , {
723
+ target : { value : "1234" } ,
724
+ } ) ;
725
+ expect ( node . querySelectorAll ( ".errors li" ) ) . to . have . length . of ( 0 ) ;
726
+ expect ( comp . state . errors ) . to . have . lengthOf ( 0 ) ;
750
727
} ) ;
751
728
} ) ;
752
729
} ) ;
0 commit comments