diff --git a/js/src/carousel.js b/js/src/carousel.js index a956ebc8bb..fa401535af 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -498,7 +498,14 @@ class Carousel extends BaseComponent { static carouselInterface(element, config) { const data = Carousel.getOrCreateInstance(element, config) - const { _config } = data + let { _config } = data + if (typeof config === 'object') { + _config = { + ..._config, + ...config + } + } + const action = typeof config === 'string' ? config : _config.slide if (typeof config === 'number') { diff --git a/js/tests/unit/carousel.spec.js b/js/tests/unit/carousel.spec.js index 5120cc6015..74f82ce1f0 100644 --- a/js/tests/unit/carousel.spec.js +++ b/js/tests/unit/carousel.spec.js @@ -707,6 +707,34 @@ describe('Carousel', () => { carousel.next() }) + + it('should call next()/prev() instance methods when clicking the respective direction buttons', () => { + fixtureEl.innerHTML = [ + '' + ].join('') + + const carouselEl = fixtureEl.querySelector('#carousel') + const prevBtnEl = fixtureEl.querySelector('.carousel-control-prev') + const nextBtnEl = fixtureEl.querySelector('.carousel-control-next') + + const carousel = new Carousel(carouselEl) + const nextSpy = spyOn(carousel, 'next') + const prevSpy = spyOn(carousel, 'prev') + + nextBtnEl.click() + prevBtnEl.click() + + expect(nextSpy).toHaveBeenCalled() + expect(prevSpy).toHaveBeenCalled() + }) }) describe('nextWhenVisible', () => {