aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2019-01-04 17:15:01 +0100
committerXhmikosR <[email protected]>2019-01-04 18:15:01 +0200
commit89a73f100e7a3c765314e5cff0eeaf9c051f2944 (patch)
tree7acd975e91e78372af7cb234e94a54056aa93a61 /js
parentd4b5b4b78c936f9a9d38d52ca5be1cbdee26ee54 (diff)
downloadbootstrap-89a73f100e7a3c765314e5cff0eeaf9c051f2944.tar.xz
bootstrap-89a73f100e7a3c765314e5cff0eeaf9c051f2944.zip
carousel should not cycle when there is no data-ride on init (#27968)
Diffstat (limited to 'js')
-rw-r--r--js/src/carousel.js2
-rw-r--r--js/tests/unit/carousel.js47
2 files changed, 48 insertions, 1 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 21ec57a2e..a43d86b18 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -531,7 +531,7 @@ class Carousel {
throw new TypeError(`No method named "${action}"`)
}
data[action]()
- } else if (_config.interval) {
+ } else if (_config.interval && _config.ride) {
data.pause()
data.cycle()
}
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js
index d6fea2f34..6c28b6721 100644
--- a/js/tests/unit/carousel.js
+++ b/js/tests/unit/carousel.js
@@ -1270,4 +1270,51 @@ $(function () {
assert.strictEqual(spy.called, true)
sandbox.restore()
})
+
+ QUnit.test('should not cycle when there is no attribute data-ride', function (assert) {
+ assert.expect(1)
+
+ var spy = sinon.spy(Carousel.prototype, 'cycle')
+
+ var carouselHTML = '<div class="carousel"></div>'
+ var $carousel = $(carouselHTML)
+ $carousel.appendTo('#qunit-fixture')
+ $carousel.bootstrapCarousel()
+
+ assert.strictEqual(spy.called, false)
+ spy.restore()
+ })
+
+ QUnit.test('should cycle when there is data-ride attribute', function (assert) {
+ assert.expect(1)
+
+ var spy = sinon.spy(Carousel.prototype, 'cycle')
+
+ var carouselHTML = '<div class="carousel" data-ride="carousel"></div>'
+ var $carousel = $(carouselHTML)
+ $carousel.appendTo('#qunit-fixture')
+ $carousel.bootstrapCarousel()
+
+ assert.strictEqual(spy.called, true)
+ spy.restore()
+ })
+
+ QUnit.test('should init carousels with data-ride on load event', function (assert) {
+ assert.expect(1)
+
+ var done = assert.async()
+ var spy = sinon.spy(Carousel, '_jQueryInterface')
+
+ var carouselHTML = '<div class="carousel" data-ride="carousel"></div>'
+ var $carousel = $(carouselHTML)
+ $carousel.appendTo('#qunit-fixture')
+
+ $(window).trigger($.Event('load'))
+
+ setTimeout(function () {
+ assert.strictEqual(spy.called, true)
+ spy.restore()
+ done()
+ }, 5)
+ })
})