Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohann-S <johann.servoire@gmail.com>2015-09-16 11:35:29 +0300
committerJohann-S <johann.servoire@gmail.com>2015-10-02 11:01:24 +0300
commit21a65f181eebc3f2c0cd43fb3383ee3de673745b (patch)
tree72a1c5e6da10a3dd7c918e05d0eff6a4d8e0c0aa
parentc34fdd415e864e5e6a64f36a0278b5d43c15d3a2 (diff)
Add throw error for undefined method on plugins
-rw-r--r--js/src/carousel.js7
-rw-r--r--js/src/collapse.js3
-rw-r--r--js/src/dropdown.js3
-rw-r--r--js/src/modal.js4
-rw-r--r--js/src/popover.js3
-rw-r--r--js/src/scrollspy.js3
-rw-r--r--js/src/tab.js3
-rw-r--r--js/src/tooltip.js3
-rw-r--r--js/tests/unit/carousel.js12
-rw-r--r--js/tests/unit/collapse.js12
-rw-r--r--js/tests/unit/dropdown.js12
-rw-r--r--js/tests/unit/modal.js12
-rw-r--r--js/tests/unit/popover.js12
-rw-r--r--js/tests/unit/scrollspy.js12
-rw-r--r--js/tests/unit/tab.js12
-rw-r--r--js/tests/unit/tooltip.js12
16 files changed, 121 insertions, 4 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index efacd9494e..d8da854a22 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 e46d3ec604..a9980926e0 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 734e643127..f947d2aa11 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 f57131e7e0..99a49f148f 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 b8b24a1c4c..11ee86e70c 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 27a91958ef..bdbd6439c9 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 4b311c24e3..1283881e4c 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 151cd6f515..b80bd8e8c9 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 017bd9beee..d6d0186e15 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 78fafc6c2d..4eadc205be 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 566b50ee7e..e6cda58d40 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 6da09e3c6e..50baac8a3a 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 894468695c..fcd7791d20 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 574422ef13..878c4d389d 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 1eed75e90e..2e01432930 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 934e26b9e0..9ec5ddb037 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/>')