mirror of https://github.com/twbs/bootstrap.git
				
				
				
			Add throw error for undefined method on plugins
This commit is contained in:
		
							parent
							
								
									c34fdd415e
								
							
						
					
					
						commit
						21a65f181e
					
				| 
						 | 
					@ -390,10 +390,11 @@ const Carousel = (($) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'number') {
 | 
					        if (typeof config === 'number') {
 | 
				
			||||||
          data.to(config)
 | 
					          data.to(config)
 | 
				
			||||||
 | 
					        } else if (typeof action === 'string') {
 | 
				
			||||||
        } else if (action) {
 | 
					          if (data[action] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${action}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[action]()
 | 
					          data[action]()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else if (_config.interval) {
 | 
					        } else if (_config.interval) {
 | 
				
			||||||
          data.pause()
 | 
					          data.pause()
 | 
				
			||||||
          data.cycle()
 | 
					          data.cycle()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -333,6 +333,9 @@ const Collapse = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config]()
 | 
					          data[config]()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,6 +143,9 @@ const Dropdown = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config].call(this)
 | 
					          data[config].call(this)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -463,8 +463,10 @@ const Modal = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config](relatedTarget)
 | 
					          data[config](relatedTarget)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else if (_config.show) {
 | 
					        } else if (_config.show) {
 | 
				
			||||||
          data.show(relatedTarget)
 | 
					          data.show(relatedTarget)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,6 +153,9 @@ const Popover = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config]()
 | 
					          data[config]()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -277,6 +277,9 @@ const ScrollSpy = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config]()
 | 
					          data[config]()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,6 +234,9 @@ const Tab = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config]()
 | 
					          data[config]()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -622,6 +622,9 @@ const Tooltip = (($) => {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (typeof config === 'string') {
 | 
					        if (typeof config === 'string') {
 | 
				
			||||||
 | 
					          if (data[config] === undefined) {
 | 
				
			||||||
 | 
					            throw new Error(`No method named "${config}"`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          data[config]()
 | 
					          data[config]()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.collapse, undefined, 'collapse was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div id="modal-test"/>')
 | 
					    var $el = $('<div id="modal-test"/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +25,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.popover, undefined, 'popover was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.tab, undefined, 'tab was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +25,18 @@ $(function () {
 | 
				
			||||||
    assert.strictEqual($.fn.tooltip, undefined, 'tooltip was set back to undefined (org value)')
 | 
					    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) {
 | 
					  QUnit.test('should return jquery collection containing the element', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var $el = $('<div/>')
 | 
					    var $el = $('<div/>')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue