diff --git a/js/src/carousel.js b/js/src/carousel.js index efacd9494e06d6451d535000f54104a15cf2b824..d8da854a22061fcbfcb8895edf6b5b0c15880624 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -390,10 +390,11 @@ const Carousel = (($) => { if (typeof config === 'number') { data.to(config) - - } else if (action) { + } else if (typeof action === 'string') { + if (data[action] === undefined) { + throw new Error(`No method named "${action}"`) + } data[action]() - } else if (_config.interval) { data.pause() data.cycle() diff --git a/js/src/collapse.js b/js/src/collapse.js index e46d3ec60426ccdf72feda21f2709cd75e4a1163..a9980926e03e38d8e119ae9471edf63e9065362d 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -333,6 +333,9 @@ const Collapse = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config]() } }) diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 734e64312784ec984f8bbf03f357e0c50e256e84..f947d2aa11fc75449129d6d90f54c9e389239846 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -143,6 +143,9 @@ const Dropdown = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config].call(this) } }) diff --git a/js/src/modal.js b/js/src/modal.js index f57131e7e05bbbe99abf991741fd90b03d1df49f..99a49f148f926265caaf48fd6b531db38a2d5de4 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -463,8 +463,10 @@ const Modal = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config](relatedTarget) - } else if (_config.show) { data.show(relatedTarget) } diff --git a/js/src/popover.js b/js/src/popover.js index b8b24a1c4c3036992d6e0c9a7f893a04759b7f81..11ee86e70ccfe34890914ac5d6803d4ae453b133 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -153,6 +153,9 @@ const Popover = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config]() } }) diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 27a91958efe2f4a027a5d88bdcd98385c500f6c7..bdbd6439c98fcd964d08af8f7b8be95f0f852f0e 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -277,6 +277,9 @@ const ScrollSpy = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config]() } }) diff --git a/js/src/tab.js b/js/src/tab.js index 4b311c24e35e7043f5603bb31d52ab8d8833448d..1283881e4c795eacc4b1eb481581a6969b71bdd0 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -234,6 +234,9 @@ const Tab = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config]() } }) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 151cd6f515ea9c7148488284570db36c1ad1c930..b80bd8e8c972a3d285090f4531e4e65bbf700d61 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -622,6 +622,9 @@ const Tooltip = (($) => { } if (typeof config === 'string') { + if (data[config] === undefined) { + throw new Error(`No method named "${config}"`) + } data[config]() } }) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 017bd9beeee142cdc3b26ebe1e122aacd70235e3..d6d0186e15d0dc2b0d6486bb34dc6eb97b6f8965 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapCarousel() + try { + $el.bootstrapCarousel('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 78fafc6c2d8826d4e6724413f3e370da7770ea78..4eadc205bef9f486eaa434dad9e584a51e4680ed 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.collapse, undefined, 'collapse was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapCollapse() + try { + $el.bootstrapCollapse('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 566b50ee7e124236ad5ce1c176d36f17ba1766e7..e6cda58d40107b9ed5a5d9538f47b6eb686b864f 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapDropdown() + try { + $el.bootstrapDropdown('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 6da09e3c6e2369f20217619246a1a57936b9dfda..50baac8a3a7c5e5f544b2ced484d6487c4f6175e 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div id="modal-test"/>') + $el.bootstrapModal() + try { + $el.bootstrapModal('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div id="modal-test"/>') diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 894468695ce2c989eae6745aac23224126278137..fcd7791d20fb88e179be9156688c8f13be49c5fa 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -25,6 +25,18 @@ $(function () { assert.strictEqual($.fn.popover, undefined, 'popover was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapPopover() + try { + $el.bootstrapPopover('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 574422ef131737fa7e75835284a0597d632045dd..878c4d389d6eb9288ad753da1f83f8dff7f61759 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapScrollspy() + try { + $el.bootstrapScrollspy('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 1eed75e90e3f8190acad8bdf36611f4d83edd9f6..2e01432930b427d78f240522d443a1776d7ec4fe 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -24,6 +24,18 @@ $(function () { assert.strictEqual($.fn.tab, undefined, 'tab was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapTab() + try { + $el.bootstrapTab('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 934e26b9e0da5342d6bc77eaf71e1dab0b060e0a..9ec5ddb037b74bb913506769030b6057ae234d79 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -25,6 +25,18 @@ $(function () { assert.strictEqual($.fn.tooltip, undefined, 'tooltip was set back to undefined (org value)') }) + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapTooltip() + try { + $el.bootstrapTooltip('noMethod') + } + catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + QUnit.test('should return jquery collection containing the element', function (assert) { assert.expect(2) var $el = $('<div/>')