Skip to content

Commit 7d61ece

Browse files
committed
tests(carousel): fix false positive issues through simplification
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).
1 parent 1d4294b commit 7d61ece

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

test/CarouselSpec.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,36 +316,21 @@ describe('<Carousel>', () => {
316316
});
317317

318318
it('should go through the items given the specified intervals', () => {
319-
const defaultInterval = 5000;
320-
const intervals = [
321-
1000,
322-
500,
323-
defaultInterval, // to test for no interval specified, it should be the default
324-
];
325-
const itemsWithIntervals = [
326-
<Carousel.Item key={1} interval={intervals[0]}>
327-
Item 1 content
328-
</Carousel.Item>,
329-
<Carousel.Item key={2} interval={intervals[1]}>
330-
Item 2 content
331-
</Carousel.Item>,
332-
<Carousel.Item key={3}>Item 3 content</Carousel.Item>,
333-
];
334-
335319
const onSelectSpy = sinon.spy();
336320
mount(
337-
<Carousel interval={defaultInterval} onSelect={onSelectSpy}>
338-
{itemsWithIntervals}
321+
<Carousel interval={1000} onSelect={onSelectSpy}>
322+
<Carousel.Item interval={100}>Item 1 content</Carousel.Item>
323+
<Carousel.Item>Item 2 content</Carousel.Item>
339324
</Carousel>,
340325
);
341326

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

345-
expect(onSelectSpy).to.have.been.calledThrice;
332+
expect(onSelectSpy).to.have.been.calledOnce;
346333
expect(onSelectSpy.firstCall).to.have.been.calledWith(1);
347-
expect(onSelectSpy.secondCall).to.have.been.calledWith(2);
348-
expect(onSelectSpy.thirdCall).to.have.been.calledWith(0);
349334
});
350335

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

0 commit comments

Comments
 (0)