Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #17612][V4] Throw explicit error when a nonexistent method is invoked #17616

Merged
merged 1 commit into from
Oct 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@ const Carousel = (($) => {

if (typeof config === 'number') {
data.to(config)

} else if (action) {
} else if (typeof action === 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why'd you change the condition here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because action is always a string.

But if you prefer I can restore the old condition

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's okay.

if (data[action] === undefined) {
throw new Error(`No method named "${action}"`)
}
data[action]()

} else if (_config.interval) {
data.pause()
data.cycle()
Expand Down
3 changes: 3 additions & 0 deletions js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ const Collapse = (($) => {
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
Expand Down
3 changes: 3 additions & 0 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
4 changes: 3 additions & 1 deletion js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions js/src/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ const Popover = (($) => {
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
Expand Down
3 changes: 3 additions & 0 deletions js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ const ScrollSpy = (($) => {
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
Expand Down
3 changes: 3 additions & 0 deletions js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ const Tab = (($) => {
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
Expand Down
3 changes: 3 additions & 0 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ const Tooltip = (($) => {
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/>')
Expand Down