diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js
index 2c3fd0cb04..a25df3a58d 100644
--- a/js/tests/unit/popover.js
+++ b/js/tests/unit/popover.js
@@ -259,6 +259,16 @@ $(function () {
assert.strictEqual($popover.data('bs.popover'), undefined, 'should not initialize the popover')
})
+ QUnit.test('should throw an error when template contains multiple top-level elements', function (assert) {
+ assert.expect(1)
+ assert.throws(function () {
+ $('some text')
+ .appendTo('#qunit-fixture')
+ .bootstrapPopover({ template: '
Foo
Bar
' })
+ .bootstrapPopover('show')
+ }, new Error('popover `template` option must consist of exactly 1 top-level element!'))
+ })
+
QUnit.test('should fire inserted event', function (assert) {
assert.expect(2)
var done = assert.async()
@@ -276,4 +286,5 @@ $(function () {
})
.bootstrapPopover('show')
})
+
})
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 0cb964e9b6..2c492a92bb 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -1225,4 +1225,14 @@ $(function () {
assert.strictEqual($tooltip.data('bs.tooltip'), undefined, 'should not initialize the tooltip')
})
+ QUnit.test('should throw an error when template contains multiple top-level elements', function (assert) {
+ assert.expect(1)
+ assert.throws(function () {
+ $('')
+ .appendTo('#qunit-fixture')
+ .bootstrapTooltip({ template: 'Foo
Bar
' })
+ .bootstrapTooltip('show')
+ }, new Error('tooltip `template` option must consist of exactly 1 top-level element!'))
+ })
+
})
diff --git a/js/tooltip.js b/js/tooltip.js
index b2d775938a..2d42cab24c 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -404,7 +404,13 @@
}
Tooltip.prototype.tip = function () {
- return (this.$tip = this.$tip || $(this.options.template))
+ if (!this.$tip) {
+ this.$tip = $(this.options.template)
+ if (this.$tip.length != 1) {
+ throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!')
+ }
+ }
+ return this.$tip
}
Tooltip.prototype.arrow = function () {