diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 7ae35e2e87..3be4d67ad6 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -225,4 +225,11 @@ $(function () { }) .bootstrapPopover('show') }) + + test('should throw an error when initializing popover on the document object without specifying a delegation selector', function () { + throws(function () { + $(document).bootstrapPopover({ title: 'What am I on?', content: 'My selector is missing' }) + }, new Error('`selector` option must be specified when initializing popover on the window.document object!')) + }) + }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 38298bdd82..b734218b90 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1107,4 +1107,10 @@ $(function () { $element.bootstrapTooltip('show') }) + test('should throw an error when initializing tooltip on the document object without specifying a delegation selector', function () { + throws(function () { + $(document).bootstrapTooltip({ title: 'What am I on?' }) + }, new Error('`selector` option must be specified when initializing tooltip on the window.document object!')) + }) + }) diff --git a/js/tooltip.js b/js/tooltip.js index f056fbc765..fb2ff7b9a0 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -52,6 +52,10 @@ this.options = this.getOptions(options) this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport) + if (this.$element[0] instanceof document.constructor && !this.options.selector) { + throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!'); + } + var triggers = this.options.trigger.split(' ') for (var i = triggers.length; i--;) {