@@ -629,6 +629,76 @@ describe("VueFormGenerator.vue", () => {
629629
630630 } ) ;
631631
632+ describe . only ( "check onValidated event" , ( ) => {
633+ let schema = {
634+ fields : [
635+ {
636+ type : "input" ,
637+ inputType : "text" ,
638+ label : "Name" ,
639+ model : "name" ,
640+ min : 3 ,
641+ validator : VueFormGenerator . validators . string
642+ }
643+ ]
644+ } ;
645+
646+ let model = { name : "Bob" } ;
647+ let form ;
648+ let onValidated = sinon . spy ( ) ;
649+
650+ before ( ( done ) => {
651+ let elm = document . createElement ( "div" ) ;
652+ vm = new Vue ( {
653+ // eslint-disable-next-line quotes
654+ template : `<vue-form-generator :schema="schema" :model="model" :options="options" :multiple="false" ref="form" @on-validated="onValidated"></vue-form-generator>` ,
655+ data : {
656+ schema,
657+ model,
658+ options : { }
659+ } ,
660+ methods : {
661+ onValidated
662+ }
663+ } ) . $mount ( elm ) ;
664+
665+ el = vm . $el ;
666+ vm . $nextTick ( ( ) => {
667+ form = vm . $refs . form ;
668+ done ( ) ;
669+ } ) ;
670+ } ) ;
671+
672+ it ( "should no errors after mounted()" , ( done ) => {
673+ vm . $nextTick ( ( ) => {
674+ expect ( form . errors ) . to . be . length ( 0 ) ;
675+ done ( ) ;
676+ } ) ;
677+ } ) ;
678+
679+ it ( "should be validation error if model value is not valid" , ( ) => {
680+ vm . model . name = "A" ;
681+ onValidated . reset ( ) ;
682+ form . validate ( ) ;
683+
684+ expect ( form . errors ) . to . be . length ( 1 ) ;
685+ expect ( onValidated . callCount ) . to . be . equal ( 1 ) ;
686+ // console.log(onValidated.getCall(0).args[1][0].field);
687+ // console.log(schema.fields[0]);
688+ expect ( onValidated . calledWith ( false , [ { field : schema . fields [ 0 ] , error : "The length of text is too small! Current: 1, Minimum: 3" } ] ) ) . to . be . true ;
689+ } ) ;
690+
691+ it ( "should no validation error if model valie is valid" , ( ) => {
692+ vm . model . name = "Alan" ;
693+ onValidated . reset ( ) ;
694+ form . validate ( ) ;
695+
696+ expect ( form . errors ) . to . be . length ( 0 ) ;
697+ expect ( onValidated . callCount ) . to . be . equal ( 1 ) ;
698+ expect ( onValidated . calledWith ( true , [ ] ) ) . to . be . true ;
699+ } ) ;
700+ } ) ;
701+
632702 describe ( "check schema.onChanged when the model changed" , ( ) => {
633703 let schema = {
634704 fields : [
0 commit comments