Skip to content

Commit

Permalink
tests(carousel): fix false positive issues through simplification
Browse files Browse the repository at this point in the history
Fixes the false positive issues by simplifying the assertions made
to verify its most basic use case (e.g. assert after automatically
sliding the first element and check if we're still on the second
element).
  • Loading branch information
bpas247 committed Aug 7, 2020
1 parent 1d4294b commit 7d61ece
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions test/CarouselSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,36 +316,21 @@ describe('<Carousel>', () => {
});

it('should go through the items given the specified intervals', () => {
const defaultInterval = 5000;
const intervals = [
1000,
500,
defaultInterval, // to test for no interval specified, it should be the default
];
const itemsWithIntervals = [
<Carousel.Item key={1} interval={intervals[0]}>
Item 1 content
</Carousel.Item>,
<Carousel.Item key={2} interval={intervals[1]}>
Item 2 content
</Carousel.Item>,
<Carousel.Item key={3}>Item 3 content</Carousel.Item>,
];

const onSelectSpy = sinon.spy();
mount(
<Carousel interval={defaultInterval} onSelect={onSelectSpy}>
{itemsWithIntervals}
<Carousel interval={1000} onSelect={onSelectSpy}>
<Carousel.Item interval={100}>Item 1 content</Carousel.Item>
<Carousel.Item>Item 2 content</Carousel.Item>
</Carousel>,
);

const total = intervals.reduce((sum, current) => sum + current, 0);
clock.tick(total * 1.1);
// should be long enough to handle false positive issues
// but short enough to not trigger auto-play to occur twice
// (since the interval for the second item should be `1000`)
clock.tick(200);

expect(onSelectSpy).to.have.been.calledThrice;
expect(onSelectSpy).to.have.been.calledOnce;
expect(onSelectSpy.firstCall).to.have.been.calledWith(1);
expect(onSelectSpy.secondCall).to.have.been.calledWith(2);
expect(onSelectSpy.thirdCall).to.have.been.calledWith(0);
});

it('should stop going through items on hover and continue afterwards', () => {
Expand Down

0 comments on commit 7d61ece

Please sign in to comment.