From 2b437b3bedd3918026e1f3ea98f83801aa639dbe Mon Sep 17 00:00:00 2001 From: dercodercom Date: Sat, 20 Jan 2018 17:58:25 +0100 Subject: [PATCH 1/2] Update tab.js I'm using Tab.js with remove function and get an error "TypeError: container is undefined [more info]", with this check the error is fixed. --- js/src/tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/tab.js b/js/src/tab.js index af296f74fe21..7333f22a1f86 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -142,7 +142,7 @@ class Tab { _activate(element, container, callback) { let activeElements - if (container.nodeName === 'UL') { + if (container && container.nodeName === 'UL') { activeElements = $(container).find(Selector.ACTIVE_UL) } else { activeElements = $(container).children(Selector.ACTIVE) From 16bdbb656a8a4e7fb8a553b38e03b4ddf025ee74 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Mon, 29 Oct 2018 13:29:37 +0100 Subject: [PATCH 2/2] add unit test to test tabs can be removed without throwing error --- js/tests/unit/tab.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index e28ca83a756e..3ce29b662408 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -414,4 +414,49 @@ $(function () { }) .trigger($.Event('click')) }) + + QUnit.test('should handle removed tabs', function (assert) { + assert.expect(1) + var done = assert.async() + + var html = [ + '', + '
', + '
test 1
', + '
test 2
', + '
test 3
', + '
' + ].join('') + + $(html).appendTo('#qunit-fixture') + + $('#secondNav').on('shown.bs.tab', function () { + assert.strictEqual($('.nav-tab').length, 2) + done() + }) + + $('#btnClose').one('click', function () { + var tabId = $(this).parents('a').attr('href') + $(this).parents('li').remove() + $(tabId).remove() + $('.nav-tabs a:last').bootstrapTab('show') + }) + .trigger($.Event('click')) + }) })