@@ -8,29 +8,31 @@ Vue.use(VueFormGenerator);
88let el , vm ;
99
1010function createFormGenerator ( schema = { } , model = null , options , multiple ) {
11- el = document . createElement ( "div" ) ;
12- // eslint-disable-next-line quotes
13- el . innerHTML = `<vue-form-generator :schema="schema" :model="model" :options="options" :multiple="multiple" ref="form"></vue-form-generator>` ;
11+ let elm = document . createElement ( "div" ) ;
1412 vm = new Vue ( {
13+ // eslint-disable-next-line quotes
14+ template : `<vue-form-generator :schema="schema" :model="model" :options="options" :multiple="multiple" ref="form"></vue-form-generator>` ,
1515 data : {
1616 schema,
1717 model,
1818 options,
1919 multiple
2020 }
21- } ) . $mount ( el ) ;
21+ } ) . $mount ( elm ) ;
22+ /*
23+ vm.$nextTick(() => {
24+ console.log(el);
25+ console.log(vm.$el);
2226
23- // console.log(el);
27+ });
28+ */
29+ el = vm . $el ;
2430
2531 return [ el , vm ] ;
2632}
2733
2834describe ( "VueFormGenerator.vue" , ( ) => {
29- describe . only ( "nothing" , ( ) => {
30- it ( "should do nothing" , ( ) => {
31- expect ( [ ] ) . to . be . length ( 0 ) ;
32- } ) ;
33- } ) ;
35+
3436 describe ( "with empty schema" , ( ) => {
3537 let schema = { } ;
3638
@@ -105,23 +107,23 @@ describe("VueFormGenerator.vue", () => {
105107 } ) ;
106108
107109 it ( "should be error class" , ( done ) => {
108- vm . $ set( " schema.fields[0]. errors", [ "!!!" ] ) ;
110+ Vue . set ( vm . schema . fields [ 0 ] , " errors", [ "!!!" ] ) ;
109111 vm . $nextTick ( ( ) => {
110112 expect ( group . classList . contains ( "error" ) ) . to . be . true ;
111113 done ( ) ;
112114 } ) ;
113115 } ) ;
114116
115117 it ( "should be add a custom classes" , ( done ) => {
116- vm . $ set( " schema.fields[0]. styleClasses", "classA" ) ;
118+ Vue . set ( vm . schema . fields [ 0 ] , " styleClasses", "classA" ) ;
117119 vm . $nextTick ( ( ) => {
118120 expect ( group . classList . contains ( "classA" ) ) . to . be . true ;
119121 done ( ) ;
120122 } ) ;
121123 } ) ;
122124
123125 it ( "should be add more custom classes" , ( done ) => {
124- vm . $ set( " schema.fields[0]. styleClasses", [ "classB" , "classC" ] ) ;
126+ Vue . set ( vm . schema . fields [ 0 ] , " styleClasses", [ "classB" , "classC" ] ) ;
125127 vm . $nextTick ( ( ) => {
126128 expect ( group . classList . contains ( "classB" ) ) . to . be . true ;
127129 expect ( group . classList . contains ( "classC" ) ) . to . be . true ;
@@ -466,9 +468,12 @@ describe("VueFormGenerator.vue", () => {
466468 let model = { name : "Me" } ;
467469 let form ;
468470
469- before ( ( ) => {
471+ before ( ( done ) => {
470472 createFormGenerator ( schema , model , { validateAfterLoad : true } ) ;
471- form = vm . $refs . form ;
473+ vm . $nextTick ( ( ) => {
474+ form = vm . $refs . form ;
475+ done ( ) ;
476+ } ) ;
472477 } ) ;
473478
474479 it ( "should be validation error at mounted()" , ( done ) => {
@@ -480,27 +485,27 @@ describe("VueFormGenerator.vue", () => {
480485
481486 it ( "should be validation error if model is changed" , ( done ) => {
482487 form . model = { name : "Al" } ;
483- vm . $nextTick ( ( ) => {
488+ setTimeout ( ( ) => {
484489 expect ( form . errors ) . to . be . length ( 1 ) ;
485490 done ( ) ;
486- } ) ;
491+ } , 150 ) ;
487492 } ) ;
488493
489494 it ( "should be no errors if model is correct" , ( done ) => {
490495 form . model = { name : "Bob" } ;
491- vm . $nextTick ( ( ) => {
496+ setTimeout ( ( ) => {
492497 expect ( form . errors ) . to . be . length ( 0 ) ;
493498 done ( ) ;
494- } ) ;
499+ } , 150 ) ;
495500 } ) ;
496501
497502 it ( "should be no errors if validateAfterLoad is false" , ( done ) => {
498503 form . options . validateAfterLoad = false ;
499504 form . model = { name : "Ed" } ;
500- vm . $nextTick ( ( ) => {
505+ setTimeout ( ( ) => {
501506 expect ( form . errors ) . to . be . length ( 0 ) ;
502507 done ( ) ;
503- } ) ;
508+ } , 150 ) ;
504509 } ) ;
505510
506511 } ) ;
0 commit comments