@@ -6,7 +6,7 @@ import LayCarousel from "../index.vue";
6
6
import LayCarouselItem from "../../carouselItem/index.vue" ;
7
7
8
8
// https://github.com/vuejs/test-utils/issues/2409
9
- vi . spyOn ( console , ' warn' ) . mockImplementation ( ( ) => { } ) ;
9
+ vi . spyOn ( console , " warn" ) . mockImplementation ( ( ) => { } ) ;
10
10
11
11
const data = [
12
12
{
@@ -30,35 +30,37 @@ const generateCarouselItems = (_data?: any[]) => {
30
30
31
31
const _mount = ( props ?: any , list ?: any [ ] ) => {
32
32
return mount ( {
33
- setup ( ) {
33
+ setup ( ) {
34
34
const data = reactive ( {
35
- modelValue : '1' ,
35
+ modelValue : "1" ,
36
36
autoplay : false ,
37
- ...props
38
- } )
37
+ ...props ,
38
+ } ) ;
39
39
40
40
return ( ) => (
41
- < LayCarousel autoplay = { data . autoplay } { ...props } v-model = { data . modelValue } >
41
+ < LayCarousel
42
+ autoplay = { data . autoplay }
43
+ { ...props }
44
+ v-model = { data . modelValue }
45
+ >
42
46
{ generateCarouselItems ( list ) }
43
47
</ LayCarousel >
44
- )
45
- }
46
- } )
47
- }
48
-
48
+ ) ;
49
+ } ,
50
+ } ) ;
51
+ } ;
49
52
50
53
describe ( "LayCarousel" , ( ) => {
51
-
52
54
test ( "Items length" , async ( ) => {
53
- const wrapper = _mount ( )
55
+ const wrapper = _mount ( ) ;
54
56
55
57
expect ( wrapper . find ( "[carousel-item]" ) . findAll ( "li" ) . length ) . toEqual ( 3 ) ;
56
58
} ) ;
57
59
58
60
test ( "vModel" , async ( ) => {
59
- const wrapper = _mount ( { modelValue : '2' } )
61
+ const wrapper = _mount ( { modelValue : "2" } ) ;
60
62
await nextTick ( ) ;
61
-
63
+
62
64
expect (
63
65
(
64
66
wrapper
@@ -80,100 +82,112 @@ describe("LayCarousel", () => {
80
82
test ( "autoplay and interval" , async ( ) => {
81
83
const wrapper = _mount ( {
82
84
autoplay : true ,
83
- interval : 500
84
- } )
85
+ interval : 500 ,
86
+ } ) ;
85
87
86
88
await nextTick ( ) ;
87
89
await wait ( ) ;
88
- const bodyItems = wrapper . vm . $el . querySelector ( '[carousel-item]' ) . querySelectorAll ( 'li' )
89
- const indicatorItems = wrapper . vm . $el . querySelector ( '.layui-carousel-ind' ) . querySelectorAll ( 'li' )
90
- expect ( bodyItems [ 0 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeTruthy ( ) ;
91
- expect ( indicatorItems [ 0 ] . classList . contains ( 'layui-this' ) ) . toBeTruthy ( )
90
+ const bodyItems = wrapper . vm . $el
91
+ . querySelector ( "[carousel-item]" )
92
+ . querySelectorAll ( "li" ) ;
93
+ const indicatorItems = wrapper . vm . $el
94
+ . querySelector ( ".layui-carousel-ind" )
95
+ . querySelectorAll ( "li" ) ;
96
+ expect (
97
+ bodyItems [ 0 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
98
+ ) . toBeTruthy ( ) ;
99
+ expect ( indicatorItems [ 0 ] . classList . contains ( "layui-this" ) ) . toBeTruthy ( ) ;
92
100
await nextTick ( ) ;
93
101
await wait ( 600 ) ;
94
- expect ( bodyItems [ 1 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeTruthy ( ) ;
95
- expect ( indicatorItems [ 1 ] . classList . contains ( 'layui-this' ) ) . toBeTruthy ( )
96
-
97
- } )
102
+ expect (
103
+ bodyItems [ 1 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
104
+ ) . toBeTruthy ( ) ;
105
+ expect ( indicatorItems [ 1 ] . classList . contains ( "layui-this" ) ) . toBeTruthy ( ) ;
106
+ } ) ;
98
107
99
- test ( ' pauseOnHover' , async ( ) => {
108
+ test ( " pauseOnHover" , async ( ) => {
100
109
const wrapper = _mount ( {
101
110
autoplay : true ,
102
- interval : 500
103
- } )
111
+ interval : 500 ,
112
+ } ) ;
104
113
105
114
await nextTick ( ) ;
106
115
await wait ( ) ;
107
- const bodyItems = wrapper . vm . $el . querySelector ( '[carousel-item]' ) . querySelectorAll ( 'li' )
108
-
109
- expect ( bodyItems [ 0 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeTruthy ( ) ;
116
+ const bodyItems = wrapper . vm . $el
117
+ . querySelector ( "[carousel-item]" )
118
+ . querySelectorAll ( "li" ) ;
110
119
111
- await wrapper . trigger ( 'mouseenter' )
112
- await nextTick ( )
113
- await wait ( 600 )
114
- expect ( bodyItems [ 0 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeTruthy ( ) ;
120
+ expect (
121
+ bodyItems [ 0 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
122
+ ) . toBeTruthy ( ) ;
115
123
116
- await wrapper . trigger ( 'mouseleave' )
117
- await nextTick ( )
118
- await wait ( 600 )
119
- expect ( bodyItems [ 0 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeFalsy ( ) ;
120
- expect ( bodyItems [ 1 ] . getAttribute ( 'style' ) . includes ( "visibility: inherit" ) ) . toBeTruthy ( ) ;
124
+ await wrapper . trigger ( "mouseenter" ) ;
125
+ await nextTick ( ) ;
126
+ await wait ( 600 ) ;
127
+ expect (
128
+ bodyItems [ 0 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
129
+ ) . toBeTruthy ( ) ;
121
130
122
- } )
131
+ await wrapper . trigger ( "mouseleave" ) ;
132
+ await nextTick ( ) ;
133
+ await wait ( 600 ) ;
134
+ expect (
135
+ bodyItems [ 0 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
136
+ ) . toBeFalsy ( ) ;
137
+ expect (
138
+ bodyItems [ 1 ] . getAttribute ( "style" ) . includes ( "visibility: inherit" )
139
+ ) . toBeTruthy ( ) ;
140
+ } ) ;
123
141
124
- test ( ' manual change' , async ( ) => {
125
- const wrapper = _mount ( )
142
+ test ( " manual change" , async ( ) => {
143
+ const wrapper = _mount ( ) ;
126
144
127
145
const Carousel = wrapper . getComponent ( LayCarousel ) ;
128
- const btn = wrapper . vm . $el . querySelectorAll ( '.layui-carousel-arrow' )
129
-
130
- await btn [ 1 ] . click ( )
131
- await nextTick ( )
132
- await wait ( ) ;
133
- expect ( Carousel . props ( 'modelValue' ) ) . toBe ( '2' )
146
+ const btn = wrapper . vm . $el . querySelectorAll ( ".layui-carousel-arrow" ) ;
134
147
135
- await btn [ 0 ] . click ( )
136
- await nextTick ( )
148
+ await btn [ 1 ] . click ( ) ;
149
+ await nextTick ( ) ;
137
150
await wait ( ) ;
138
- expect ( Carousel . props ( ' modelValue' ) ) . toBe ( '1' )
151
+ expect ( Carousel . props ( " modelValue" ) ) . toBe ( "2" ) ;
139
152
140
- await btn [ 1 ] . click ( )
141
- await btn [ 1 ] . click ( )
142
- await nextTick ( )
153
+ await btn [ 0 ] . click ( ) ;
154
+ await nextTick ( ) ;
143
155
await wait ( ) ;
144
- expect ( Carousel . props ( ' modelValue' ) ) . toBe ( '3' )
156
+ expect ( Carousel . props ( " modelValue" ) ) . toBe ( "1" ) ;
145
157
146
- await btn [ 1 ] . click ( )
147
- await nextTick ( )
158
+ await btn [ 1 ] . click ( ) ;
159
+ await btn [ 1 ] . click ( ) ;
160
+ await nextTick ( ) ;
148
161
await wait ( ) ;
149
- expect ( Carousel . props ( ' modelValue' ) ) . toBe ( '1' )
162
+ expect ( Carousel . props ( " modelValue" ) ) . toBe ( "3" ) ;
150
163
151
- } )
164
+ await btn [ 1 ] . click ( ) ;
165
+ await nextTick ( ) ;
166
+ await wait ( ) ;
167
+ expect ( Carousel . props ( "modelValue" ) ) . toBe ( "1" ) ;
168
+ } ) ;
152
169
153
- test ( ' ref' , async ( ) => {
170
+ test ( " ref" , async ( ) => {
154
171
const wrapper = _mount ( {
155
- ref : ' carousel'
156
- } )
172
+ ref : " carousel" ,
173
+ } ) ;
157
174
158
175
const Carousel = wrapper . getComponent ( LayCarousel ) ;
159
- const CarouselRef = wrapper . findComponent ( { ref : ' carousel' } ) . vm
176
+ const CarouselRef = wrapper . findComponent ( { ref : " carousel" } ) . vm ;
160
177
161
- CarouselRef . next ( )
162
- await nextTick ( )
178
+ CarouselRef . next ( ) ;
179
+ await nextTick ( ) ;
163
180
await wait ( ) ;
164
- expect ( Carousel . props ( ' modelValue' ) ) . toBe ( '2' )
181
+ expect ( Carousel . props ( " modelValue" ) ) . toBe ( "2" ) ;
165
182
166
- CarouselRef . prev ( )
167
- await nextTick ( )
183
+ CarouselRef . prev ( ) ;
184
+ await nextTick ( ) ;
168
185
await wait ( ) ;
169
- expect ( Carousel . props ( ' modelValue' ) ) . toBe ( '1' )
186
+ expect ( Carousel . props ( " modelValue" ) ) . toBe ( "1" ) ;
170
187
171
- CarouselRef . setActive ( '3' )
172
- await nextTick ( )
188
+ CarouselRef . setActive ( "3" ) ;
189
+ await nextTick ( ) ;
173
190
await wait ( ) ;
174
- expect ( Carousel . props ( 'modelValue' ) ) . toBe ( '3' )
175
-
176
- } )
177
-
178
-
191
+ expect ( Carousel . props ( "modelValue" ) ) . toBe ( "3" ) ;
192
+ } ) ;
179
193
} ) ;
0 commit comments