File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,16 @@ $(function () {
259259 assert . strictEqual ( $popover . data ( 'bs.popover' ) , undefined , 'should not initialize the popover' )
260260 } )
261261
262+ QUnit . test ( 'should throw an error when template contains multiple top-level elements' , function ( assert ) {
263+ assert . expect ( 1 )
264+ assert . throws ( function ( ) {
265+ $ ( '<span data-toggle="popover" data-title="some title" data-content="some content">some text</span>' )
266+ . appendTo ( '#qunit-fixture' )
267+ . bootstrapPopover ( { template : '<div>Foo</div><div>Bar</div>' } )
268+ . bootstrapPopover ( 'show' )
269+ } , new Error ( 'popover `template` option must consist of exactly 1 top-level element!' ) )
270+ } )
271+
262272 QUnit . test ( 'should fire inserted event' , function ( assert ) {
263273 assert . expect ( 2 )
264274 var done = assert . async ( )
@@ -276,4 +286,5 @@ $(function () {
276286 } )
277287 . bootstrapPopover ( 'show' )
278288 } )
289+
279290} )
Original file line number Diff line number Diff line change @@ -1225,4 +1225,14 @@ $(function () {
12251225 assert . strictEqual ( $tooltip . data ( 'bs.tooltip' ) , undefined , 'should not initialize the tooltip' )
12261226 } )
12271227
1228+ QUnit . test ( 'should throw an error when template contains multiple top-level elements' , function ( assert ) {
1229+ assert . expect ( 1 )
1230+ assert . throws ( function ( ) {
1231+ $ ( '<a href="#" data-toggle="tooltip" title="Another tooltip"></a>' )
1232+ . appendTo ( '#qunit-fixture' )
1233+ . bootstrapTooltip ( { template : '<div>Foo</div><div>Bar</div>' } )
1234+ . bootstrapTooltip ( 'show' )
1235+ } , new Error ( 'tooltip `template` option must consist of exactly 1 top-level element!' ) )
1236+ } )
1237+
12281238} )
Original file line number Diff line number Diff line change 404404 }
405405
406406 Tooltip . prototype . tip = function ( ) {
407- return ( this . $tip = this . $tip || $ ( this . options . template ) )
407+ if ( ! this . $tip ) {
408+ this . $tip = $ ( this . options . template )
409+ if ( this . $tip . length != 1 ) {
410+ throw new Error ( this . type + ' `template` option must consist of exactly 1 top-level element!' )
411+ }
412+ }
413+ return this . $tip
408414 }
409415
410416 Tooltip . prototype . arrow = function ( ) {
You can’t perform that action at this time.
0 commit comments