@@ -109,13 +109,15 @@ describe('Carousel', () => {
109
109
110
110
it ( 'should wrap around from the last to first slide if infinite is true and next is clicked' , done => {
111
111
const onSlideTransitionedStub = sinon . stub ( ) ;
112
+ const beforeChangeStub = sinon . stub ( ) ;
112
113
113
114
renderToJsdom (
114
115
< Carousel initialSlide = { 2 }
115
116
slideWidth = '300px'
116
117
viewportWidth = '300px'
117
118
infinite = { true }
118
- onSlideTransitioned = { onSlideTransitionedStub } >
119
+ onSlideTransitioned = { onSlideTransitionedStub }
120
+ beforeChange = { beforeChangeStub } >
119
121
< div id = 'slide1' />
120
122
< div id = 'slide2' />
121
123
< div id = 'slide3' />
@@ -136,13 +138,16 @@ describe('Carousel', () => {
136
138
index : 0 ,
137
139
direction : 'right'
138
140
} ) ;
141
+ expect ( beforeChangeStub ) . to . have . been . calledWith ( 0 , 2 , 'right' ) ;
139
142
done ( ) ;
140
143
} ) ;
141
144
} ) ;
142
145
143
146
it ( 'should wrap around from the first to last slide if infinite is true and prev is clicked' , done => {
147
+ const beforeChangeStub = sinon . stub ( ) ;
148
+
144
149
renderToJsdom (
145
- < Carousel initialSlide = { 2 } slideWidth = '300px' viewportWidth = '300px' infinite = { true } >
150
+ < Carousel initialSlide = { 0 } slideWidth = '300px' viewportWidth = '300px' infinite = { true } beforeChange = { beforeChangeStub } >
146
151
< div id = 'slide1' />
147
152
< div id = 'slide2' />
148
153
< div id = 'slide3' />
@@ -152,12 +157,13 @@ describe('Carousel', () => {
152
157
setImmediate ( ( ) => {
153
158
let dots = tree . find ( '.carousel-dot' ) ;
154
159
expect ( dots . length ) . to . equal ( 3 ) ;
155
- expect ( dots . at ( 2 ) . prop ( 'className' ) ) . to . contain ( 'selected' ) ;
156
- const nextButton = tree . find ( '.carousel-right-arrow' ) ;
157
- nextButton . simulate ( 'click' ) ;
158
- dots = tree . find ( '.carousel-dot' ) ;
159
- expect ( dots . at ( 2 ) . prop ( 'className' ) ) . to . not . contain ( 'selected' ) ;
160
160
expect ( dots . at ( 0 ) . prop ( 'className' ) ) . to . contain ( 'selected' ) ;
161
+ const prevButton = tree . find ( '.carousel-left-arrow' ) ;
162
+ prevButton . simulate ( 'click' ) ;
163
+ dots = tree . find ( '.carousel-dot' ) ;
164
+ expect ( dots . at ( 0 ) . prop ( 'className' ) ) . to . not . contain ( 'selected' ) ;
165
+ expect ( dots . at ( 2 ) . prop ( 'className' ) ) . to . contain ( 'selected' ) ;
166
+ expect ( beforeChangeStub ) . to . have . been . calledWith ( 2 , 0 , 'left' ) ;
161
167
done ( ) ;
162
168
} ) ;
163
169
} ) ;
0 commit comments