File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ export default class Carousel extends Component {
330
330
331
331
this . _animating = true ;
332
332
333
- beforeChange && beforeChange ( index , currentSlide , direction ) ;
333
+ beforeChange && beforeChange ( newIndex , currentSlide , direction ) ;
334
334
this . setState ( {
335
335
transitionDuration
336
336
} , ( ) => {
Original file line number Diff line number Diff line change @@ -141,8 +141,10 @@ describe('Carousel', () => {
141
141
} ) ;
142
142
143
143
it ( 'should wrap around from the first to last slide if infinite is true and prev is clicked' , done => {
144
+ const beforeChangeStub = sinon . stub ( ) ;
145
+
144
146
renderToJsdom (
145
- < Carousel initialSlide = { 2 } slideWidth = '300px' viewportWidth = '300px' infinite = { true } >
147
+ < Carousel initialSlide = { 0 } slideWidth = '300px' viewportWidth = '300px' infinite = { true } beforeChange = { beforeChangeStub } >
146
148
< div id = 'slide1' />
147
149
< div id = 'slide2' />
148
150
< div id = 'slide3' />
@@ -152,12 +154,13 @@ describe('Carousel', () => {
152
154
setImmediate ( ( ) => {
153
155
let dots = tree . find ( '.carousel-dot' ) ;
154
156
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
157
expect ( dots . at ( 0 ) . prop ( 'className' ) ) . to . contain ( 'selected' ) ;
158
+ const prevButton = tree . find ( '.carousel-left-arrow' ) ;
159
+ prevButton . simulate ( 'click' ) ;
160
+ dots = tree . find ( '.carousel-dot' ) ;
161
+ expect ( dots . at ( 0 ) . prop ( 'className' ) ) . to . not . contain ( 'selected' ) ;
162
+ expect ( dots . at ( 2 ) . prop ( 'className' ) ) . to . contain ( 'selected' ) ;
163
+ expect ( beforeChangeStub ) . to . have . been . calledWith ( 2 , 0 , 'left' ) ;
161
164
done ( ) ;
162
165
} ) ;
163
166
} ) ;
You can’t perform that action at this time.
0 commit comments