Skip to content

Commit 49d1be5

Browse files
committed
Fix incorrect index
Fix test to actually use previous Add condition to ensure correct value is set
1 parent e835b63 commit 49d1be5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export default class Carousel extends Component {
330330

331331
this._animating = true;
332332

333-
beforeChange && beforeChange(index, currentSlide, direction);
333+
beforeChange && beforeChange(newIndex, currentSlide, direction);
334334
this.setState({
335335
transitionDuration
336336
}, () => {

test/unit/carousel.tests.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ describe('Carousel', () => {
141141
});
142142

143143
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+
144146
renderToJsdom(
145-
<Carousel initialSlide={ 2 } slideWidth='300px' viewportWidth='300px' infinite={ true }>
147+
<Carousel initialSlide={ 0 } slideWidth='300px' viewportWidth='300px' infinite={ true } beforeChange={ beforeChangeStub }>
146148
<div id='slide1'/>
147149
<div id='slide2'/>
148150
<div id='slide3'/>
@@ -152,12 +154,13 @@ describe('Carousel', () => {
152154
setImmediate(() => {
153155
let dots = tree.find('.carousel-dot');
154156
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');
160157
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');
161164
done();
162165
});
163166
});

0 commit comments

Comments
 (0)