Skip to content

Commit 2c2d04a

Browse files
committed
add unit test to test tabs can be removed without throwing error
1 parent a282c22 commit 2c2d04a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

js/tests/unit/tab.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,49 @@ $(function () {
414414
})
415415
.trigger($.Event('click'))
416416
})
417+
418+
QUnit.test('should handle removed tabs', function (assert) {
419+
assert.expect(1)
420+
var done = assert.async()
421+
422+
var html = [
423+
'<ul class="nav nav-tabs" role="tablist">',
424+
' <li class="nav-item">',
425+
' <a class="nav-link nav-tab" href="#profile" role="tab" data-toggle="tab">',
426+
' <button class="close"><span aria-hidden="true">&times;</span></button>',
427+
' </a>',
428+
' </li>',
429+
' <li class="nav-item">',
430+
' <a id="secondNav" class="nav-link nav-tab" href="#buzz" role="tab" data-toggle="tab">',
431+
' <button class="close"><span aria-hidden="true">&times;</span></button>',
432+
' </a>',
433+
' </li>',
434+
' <li class="nav-item">',
435+
' <a class="nav-link nav-tab" href="#references" role="tab" data-toggle="tab">',
436+
' <button id="btnClose" class="close"><span aria-hidden="true">&times;</span></button>',
437+
' </a>',
438+
' </li>',
439+
'</ul>',
440+
'<div class="tab-content">',
441+
' <div role="tabpanel" class="tab-pane fade show active" id="profile">test 1</div>',
442+
' <div role="tabpanel" class="tab-pane fade" id="buzz">test 2</div>',
443+
' <div role="tabpanel" class="tab-pane fade" id="references">test 3</div>',
444+
'</div>'
445+
].join('')
446+
447+
$(html).appendTo('#qunit-fixture')
448+
449+
$('#secondNav').on('shown.bs.tab', function () {
450+
assert.strictEqual($('.nav-tab').length, 2)
451+
done()
452+
})
453+
454+
$('#btnClose').one('click', function () {
455+
var tabId = $(this).parents('a').attr('href')
456+
$(this).parents('li').remove()
457+
$(tabId).remove()
458+
$('.nav-tabs a:last').bootstrapTab('show')
459+
})
460+
.trigger($.Event('click'))
461+
})
417462
})

0 commit comments

Comments
 (0)