@@ -12,7 +12,6 @@ import Vue from "vue";
12
12
import Fake from "./helper/FakeComponent.js"
13
13
import FakeFunctional from "./helper/FakeFunctionalComponent.js"
14
14
15
-
16
15
let wrapper ;
17
16
let vm ;
18
17
let props ;
@@ -22,7 +21,16 @@ let element;
22
21
let input ;
23
22
const initialRender = "<div><header></header><div>a</div><div>b</div><div>c</div><footer></footer></div>" ;
24
23
const initialRenderRaw = "<div><div>a</div><div>b</div><div>c</div></div>" ;
25
- const initialRenderTransition = "<div><span><div>a</div><div>b</div><div>c</div></span></div>" ;
24
+ const initialRenderTransition = "<div><transition-group-stub><div>a</div><div>b</div><div>c</div></transition-group-stub></div>" ;
25
+
26
+ function normalizeHTML ( wrapper ) {
27
+ return wrapper . html ( ) . replace ( / ( \r \n \t | \n | \r \t | ) / gm, "" ) ;
28
+ }
29
+
30
+ function expectHTML ( wrapper , expected ) {
31
+ const htmlStripped = normalizeHTML ( wrapper ) ;
32
+ expect ( htmlStripped ) . toEqual ( expected ) ;
33
+ }
26
34
27
35
function getEvent ( name ) {
28
36
return Sortable . mock . calls [ 0 ] [ 1 ] [ name ] ;
@@ -39,7 +47,6 @@ describe("draggable.vue when initialized with list", () => {
39
47
resetMocks ( ) ;
40
48
items = [ "a" , "b" , "c" ] ;
41
49
wrapper = shallowMount ( draggable , {
42
- attachToDocument : true ,
43
50
propsData : {
44
51
list : items
45
52
} ,
@@ -74,7 +81,6 @@ describe("draggable.vue when initialized with list", () => {
74
81
75
82
it ( "log an error when list and value are both not null" , ( ) => {
76
83
wrapper = shallowMount ( draggable , {
77
- attachToDocument : true ,
78
84
propsData : {
79
85
list : [ ] ,
80
86
value : [ ]
@@ -88,7 +94,6 @@ describe("draggable.vue when initialized with list", () => {
88
94
89
95
it ( "warns when options is used" , ( ) => {
90
96
wrapper = shallowMount ( draggable , {
91
- attachToDocument : true ,
92
97
propsData : {
93
98
options : {
94
99
group : "led zeppelin"
@@ -103,7 +108,6 @@ describe("draggable.vue when initialized with list", () => {
103
108
104
109
it ( "warns when element is used" , ( ) => {
105
110
wrapper = shallowMount ( draggable , {
106
- attachToDocument : true ,
107
111
propsData : {
108
112
element : "li"
109
113
} ,
@@ -173,23 +177,23 @@ describe("draggable.vue when initialized with list", () => {
173
177
} )
174
178
175
179
it ( "renders root element correctly" , ( ) => {
176
- expect ( wrapper . html ( ) ) . toMatch ( / ^ < d i v > .* < \/ d i v > $ / ) ;
180
+ expect ( normalizeHTML ( wrapper ) ) . toMatch ( / ^ < d i v > .* < \/ d i v > $ / ) ;
177
181
} )
178
182
179
183
it ( "renders footer slot element correctly" , ( ) => {
180
- expect ( wrapper . html ( ) ) . toMatch ( / < f o o t e r > < \/ f o o t e r > < \/ d i v > $ / ) ;
184
+ expect ( normalizeHTML ( wrapper ) ) . toMatch ( / < f o o t e r > < \/ f o o t e r > < \/ d i v > $ / ) ;
181
185
} )
182
186
183
187
it ( "renders header slot element correctly" , ( ) => {
184
- expect ( wrapper . html ( ) ) . toMatch ( / ^ < d i v > < h e a d e r > < \/ h e a d e r > / ) ;
188
+ expect ( normalizeHTML ( wrapper ) ) . toMatch ( / ^ < d i v > < h e a d e r > < \/ h e a d e r > / ) ;
185
189
} )
186
190
187
191
it ( "renders default slot element correctly" , ( ) => {
188
- expect ( wrapper . html ( ) ) . toContain ( "<div>a</div><div>b</div><div>c</div>" ) ;
192
+ expect ( normalizeHTML ( wrapper ) ) . toContain ( "<div>a</div><div>b</div><div>c</div>" ) ;
189
193
} )
190
194
191
195
it ( "renders correctly" , ( ) => {
192
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
196
+ expectHTML ( wrapper , initialRender ) ;
193
197
} )
194
198
195
199
describe . each ( [
@@ -227,6 +231,7 @@ describe("draggable.vue when initialized with list", () => {
227
231
const computeIndexes = jest . fn ( ) ;
228
232
wrapper . setMethods ( { computeIndexes } )
229
233
wrapper . setProps ( { list : [ "c" , "d" , "e" , "f" , "g" ] } ) ;
234
+ await Vue . nextTick ( ) ;
230
235
expect ( computeIndexes ) . toHaveBeenCalled ( )
231
236
} ) ;
232
237
@@ -371,7 +376,7 @@ describe("draggable.vue when initialized with list", () => {
371
376
372
377
it ( "DOM changes should be reverted" , async ( ) => {
373
378
await Vue . nextTick ( ) ;
374
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
379
+ expectHTML ( wrapper , initialRender ) ;
375
380
} )
376
381
377
382
it ( "list should be updated" , async ( ) => {
@@ -537,7 +542,7 @@ describe("draggable.vue when initialized with list", () => {
537
542
538
543
it ( "DOM changes should be reverted" , async ( ) => {
539
544
await Vue . nextTick ( ) ;
540
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
545
+ expectHTML ( wrapper , initialRender ) ;
541
546
} )
542
547
543
548
it ( "list should be updated" , async ( ) => {
@@ -579,7 +584,7 @@ describe("draggable.vue when initialized with list", () => {
579
584
580
585
it ( "DOM changes should be reverted" , async ( ) => {
581
586
await Vue . nextTick ( ) ;
582
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
587
+ expectHTML ( wrapper , initialRender ) ;
583
588
} )
584
589
585
590
it ( "list should be updated" , async ( ) => {
@@ -627,7 +632,6 @@ describe("draggable.vue when initialized with list", () => {
627
632
beforeEach ( ( ) => {
628
633
resetMocks ( ) ;
629
634
wrapper = shallowMount ( draggable , {
630
- attachToDocument : true ,
631
635
propsData : {
632
636
list : items
633
637
} ,
@@ -659,7 +663,7 @@ describe("draggable.vue when initialized with list", () => {
659
663
660
664
it ( "DOM changes should be reverted" , async ( ) => {
661
665
await Vue . nextTick ( ) ;
662
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderRaw ) ;
666
+ expectHTML ( wrapper , initialRenderRaw ) ;
663
667
} )
664
668
665
669
it ( "list should be not updated" , async ( ) => {
@@ -689,7 +693,6 @@ describe("draggable.vue when initialized with list", () => {
689
693
beforeEach ( ( ) => {
690
694
resetMocks ( ) ;
691
695
wrapper = shallowMount ( draggable , {
692
- attachToDocument : true ,
693
696
propsData : {
694
697
list : items
695
698
} ,
@@ -724,7 +727,7 @@ describe("draggable.vue when initialized with list", () => {
724
727
725
728
it ( "DOM changes should be reverted" , async ( ) => {
726
729
await Vue . nextTick ( ) ;
727
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderRaw ) ;
730
+ expectHTML ( wrapper , initialRenderRaw ) ;
728
731
} )
729
732
730
733
it ( "list should be not updated" , async ( ) => {
@@ -763,8 +766,9 @@ describe("draggable.vue when initialized with list", () => {
763
766
[ "to-be-camelized" , 1 , "toBeCamelized" ]
764
767
] ) (
765
768
"attribute %s change for value %o, calls sortable option with %s attribute" ,
766
- ( attribute , value , sortableAttribute ) => {
769
+ async ( attribute , value , sortableAttribute ) => {
767
770
vm . $attrs = { [ attribute ] : value } ;
771
+ await Vue . nextTick ( ) ;
768
772
expect ( SortableFake . option ) . toHaveBeenCalledWith ( sortableAttribute , value ) ;
769
773
}
770
774
) ;
@@ -782,8 +786,9 @@ describe("draggable.vue when initialized with list", () => {
782
786
[ "to-be-camelized" , 1 , "toBeCamelized" ]
783
787
] ) (
784
788
"when option %s change for value %o, calls sortable option with %s attribute" ,
785
- ( attribute , value , sortableAttribute ) => {
789
+ async ( attribute , value , sortableAttribute ) => {
786
790
wrapper . setProps ( { options : { [ attribute ] : value } } ) ;
791
+ await Vue . nextTick ( ) ;
787
792
expect ( SortableFake . option ) . toHaveBeenCalledWith ( sortableAttribute , value ) ;
788
793
}
789
794
) ;
@@ -850,7 +855,6 @@ describe("draggable.vue when initialized with value", () => {
850
855
Sortable . mockClear ( ) ;
851
856
items = [ "a" , "b" , "c" ] ;
852
857
wrapper = shallowMount ( draggable , {
853
- attachToDocument : true ,
854
858
propsData : {
855
859
value : items
856
860
} ,
@@ -869,14 +873,15 @@ describe("draggable.vue when initialized with value", () => {
869
873
} ) ;
870
874
871
875
it ( "renders correctly" , ( ) => {
872
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderRaw ) ;
876
+ expectHTML ( wrapper , initialRenderRaw ) ;
873
877
} )
874
878
875
879
it ( "update indexes" , async ( ) => {
876
880
await Vue . nextTick ( ) ;
877
881
const computeIndexes = jest . fn ( ) ;
878
882
wrapper . setMethods ( { computeIndexes } )
879
883
wrapper . setProps ( { value : [ "c" , "d" , "e" , "f" , "g" ] } ) ;
884
+ await Vue . nextTick ( ) ;
880
885
expect ( computeIndexes ) . toHaveBeenCalled ( )
881
886
} ) ;
882
887
@@ -924,7 +929,7 @@ describe("draggable.vue when initialized with value", () => {
924
929
925
930
it ( "DOM changes should be reverted" , async ( ) => {
926
931
await Vue . nextTick ( ) ;
927
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderRaw ) ;
932
+ expectHTML ( wrapper , initialRenderRaw ) ;
928
933
} )
929
934
930
935
it ( "input should with updated value" , async ( ) => {
@@ -962,7 +967,7 @@ describe("draggable.vue when initialized with value", () => {
962
967
963
968
it ( "DOM changes should be reverted" , async ( ) => {
964
969
await Vue . nextTick ( ) ;
965
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderRaw ) ;
970
+ expectHTML ( wrapper , initialRenderRaw ) ;
966
971
} )
967
972
968
973
it ( "send an input event" , async ( ) => {
@@ -1014,7 +1019,6 @@ describe("draggable.vue when initialized with a transition group", () => {
1014
1019
const inside = items . map ( item => `<div>${ item } </div>` ) . join ( "" ) ;
1015
1020
const template = `<transition-group>${ inside } </transition-group>`
1016
1021
wrapper = shallowMount ( draggable , {
1017
- attachToDocument : true ,
1018
1022
propsData : {
1019
1023
value : items
1020
1024
} ,
@@ -1041,7 +1045,7 @@ describe("draggable.vue when initialized with a transition group", () => {
1041
1045
} ) ;
1042
1046
1043
1047
it ( "enders correctly" , ( ) => {
1044
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderTransition ) ;
1048
+ expectHTML ( wrapper , initialRenderTransition ) ;
1045
1049
} )
1046
1050
1047
1051
it ( "creates sortable instance with options on transition root" , ( ) => {
@@ -1086,7 +1090,7 @@ describe("draggable.vue when initialized with a transition group", () => {
1086
1090
1087
1091
it ( "DOM changes should be reverted" , async ( ) => {
1088
1092
await Vue . nextTick ( ) ;
1089
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderTransition ) ;
1093
+ expectHTML ( wrapper , initialRenderTransition ) ;
1090
1094
} )
1091
1095
1092
1096
it ( "input should with updated value" , async ( ) => {
@@ -1125,7 +1129,7 @@ describe("draggable.vue when initialized with a transition group", () => {
1125
1129
1126
1130
it ( "DOM changes should be reverted" , async ( ) => {
1127
1131
await Vue . nextTick ( ) ;
1128
- expect ( wrapper . html ( ) ) . toEqual ( initialRenderTransition ) ;
1132
+ expectHTML ( wrapper , initialRenderTransition ) ;
1129
1133
} )
1130
1134
1131
1135
it ( "send an input event" , async ( ) => {
@@ -1215,7 +1219,6 @@ describe("draggable.vue when initialized with a transition group", () => {
1215
1219
resetMocks ( ) ;
1216
1220
items = [ "a" , "b" , "c" ] ;
1217
1221
wrapper = shallowMount ( draggable , {
1218
- attachToDocument : true ,
1219
1222
propsData : {
1220
1223
list : items
1221
1224
} ,
@@ -1237,7 +1240,7 @@ describe("draggable.vue when initialized with a transition group", () => {
1237
1240
} ) ;
1238
1241
1239
1242
it ( "renders correctly" , ( ) => {
1240
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
1243
+ expectHTML ( wrapper , initialRender ) ;
1241
1244
} )
1242
1245
} ) ;
1243
1246
} ) ;
0 commit comments