Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Micajuine Ho committed Feb 16, 2021
1 parent 2205cef commit c255e0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion extensions/amp-carousel/0.1/slidescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,10 @@ export class AmpSlideScroll extends BaseSlides {
*/
showSlide_(newIndex) {
const {noOfSlides_} = this;
newIndex = dev().assertNumber(newIndex);
if (!isFiniteNumber(newIndex)) {
dev().error('Attempted to show slide that is not a number: %s', newIndex);
return;
}
if (
newIndex < 0 ||
newIndex >= noOfSlides_ ||
Expand Down
12 changes: 11 additions & 1 deletion extensions/amp-carousel/0.1/test/test-slidescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
whenUpgradedToCustomElement,
} from '../../../../src/dom';
import {installResizeObserverStub} from '../../../../testing/resize-observer-stub';
import {user} from '../../../../src/log';
import {dev, user} from '../../../../src/log';

describes.realWin(
'SlideScroll',
Expand Down Expand Up @@ -1271,6 +1271,16 @@ describes.realWin(
expect(showSlideSpy).to.have.been.calledWith(4);
});

it('should error on a non-number goToSlide', async () => {
const ampSlideScroll = await getAmpSlideScroll(true);
const impl = await ampSlideScroll.getImpl();
const devErrorSpy = env.sandbox.spy(dev(), 'error');

impl.showSlideAndTriggerAction_(NaN)
expect(devErrorSpy).to.be.calledOnce;
expect(devErrorSpy.args[0][0]).to.match(/Attempted to show slide that is not a number/);
});

it('should NOT call showSlide_ before layout', async () => {
const ampSlideScroll = await getAmpSlideScroll(
true,
Expand Down

0 comments on commit c255e0e

Please sign in to comment.