@@ -8,29 +8,31 @@ Vue.use(VueFormGenerator);
8
8
let el , vm ;
9
9
10
10
function 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" ) ;
14
12
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>` ,
15
15
data : {
16
16
schema,
17
17
model,
18
18
options,
19
19
multiple
20
20
}
21
- } ) . $mount ( el ) ;
21
+ } ) . $mount ( elm ) ;
22
+ /*
23
+ vm.$nextTick(() => {
24
+ console.log(el);
25
+ console.log(vm.$el);
22
26
23
- // console.log(el);
27
+ });
28
+ */
29
+ el = vm . $el ;
24
30
25
31
return [ el , vm ] ;
26
32
}
27
33
28
34
describe ( "VueFormGenerator.vue" , ( ) => {
29
- describe . only ( "nothing" , ( ) => {
30
- it ( "should do nothing" , ( ) => {
31
- expect ( [ ] ) . to . be . length ( 0 ) ;
32
- } ) ;
33
- } ) ;
35
+
34
36
describe ( "with empty schema" , ( ) => {
35
37
let schema = { } ;
36
38
@@ -105,23 +107,23 @@ describe("VueFormGenerator.vue", () => {
105
107
} ) ;
106
108
107
109
it ( "should be error class" , ( done ) => {
108
- vm . $ set( " schema.fields[0]. errors", [ "!!!" ] ) ;
110
+ Vue . set ( vm . schema . fields [ 0 ] , " errors", [ "!!!" ] ) ;
109
111
vm . $nextTick ( ( ) => {
110
112
expect ( group . classList . contains ( "error" ) ) . to . be . true ;
111
113
done ( ) ;
112
114
} ) ;
113
115
} ) ;
114
116
115
117
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" ) ;
117
119
vm . $nextTick ( ( ) => {
118
120
expect ( group . classList . contains ( "classA" ) ) . to . be . true ;
119
121
done ( ) ;
120
122
} ) ;
121
123
} ) ;
122
124
123
125
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" ] ) ;
125
127
vm . $nextTick ( ( ) => {
126
128
expect ( group . classList . contains ( "classB" ) ) . to . be . true ;
127
129
expect ( group . classList . contains ( "classC" ) ) . to . be . true ;
@@ -466,9 +468,12 @@ describe("VueFormGenerator.vue", () => {
466
468
let model = { name : "Me" } ;
467
469
let form ;
468
470
469
- before ( ( ) => {
471
+ before ( ( done ) => {
470
472
createFormGenerator ( schema , model , { validateAfterLoad : true } ) ;
471
- form = vm . $refs . form ;
473
+ vm . $nextTick ( ( ) => {
474
+ form = vm . $refs . form ;
475
+ done ( ) ;
476
+ } ) ;
472
477
} ) ;
473
478
474
479
it ( "should be validation error at mounted()" , ( done ) => {
@@ -480,27 +485,27 @@ describe("VueFormGenerator.vue", () => {
480
485
481
486
it ( "should be validation error if model is changed" , ( done ) => {
482
487
form . model = { name : "Al" } ;
483
- vm . $nextTick ( ( ) => {
488
+ setTimeout ( ( ) => {
484
489
expect ( form . errors ) . to . be . length ( 1 ) ;
485
490
done ( ) ;
486
- } ) ;
491
+ } , 150 ) ;
487
492
} ) ;
488
493
489
494
it ( "should be no errors if model is correct" , ( done ) => {
490
495
form . model = { name : "Bob" } ;
491
- vm . $nextTick ( ( ) => {
496
+ setTimeout ( ( ) => {
492
497
expect ( form . errors ) . to . be . length ( 0 ) ;
493
498
done ( ) ;
494
- } ) ;
499
+ } , 150 ) ;
495
500
} ) ;
496
501
497
502
it ( "should be no errors if validateAfterLoad is false" , ( done ) => {
498
503
form . options . validateAfterLoad = false ;
499
504
form . model = { name : "Ed" } ;
500
- vm . $nextTick ( ( ) => {
505
+ setTimeout ( ( ) => {
501
506
expect ( form . errors ) . to . be . length ( 0 ) ;
502
507
done ( ) ;
503
- } ) ;
508
+ } , 150 ) ;
504
509
} ) ;
505
510
506
511
} ) ;
0 commit comments