aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorPhil Hughes <[email protected]>2014-10-10 15:50:00 +0100
committerHeinrich Fenkart <[email protected]>2014-10-22 21:42:35 +0200
commitab8dbc214e7ea43fec65c4464b8db7392f3df905 (patch)
tree7e43f619992cc91b5ca27c1b8e4a3e7cdafd0213 /js/tests
parent40c309b39aae2620ac501447f59eed23612e72fd (diff)
downloadbootstrap-ab8dbc214e7ea43fec65c4464b8db7392f3df905.tar.xz
bootstrap-ab8dbc214e7ea43fec65c4464b8db7392f3df905.zip
Implement `hide` and `hidden` events for tabs
Closes #14772.
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/tab.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js
index 8e50614ec..6fbf36c50 100644
--- a/js/tests/unit/tab.js
+++ b/js/tests/unit/tab.js
@@ -101,4 +101,81 @@ $(function () {
.bootstrapTab('show')
})
+ test('should fire hide and hidden events', function () {
+ stop()
+
+ var tabsHTML = '<ul class="tabs">'
+ + '<li><a href="#home">Home</a></li>'
+ + '<li><a href="#profile">Profile</a></li>'
+ + '</ul>'
+
+ $(tabsHTML)
+ .find('li:first a')
+ .on('hide.bs.tab', function () {
+ ok(true, 'hide event fired')
+ })
+ .bootstrapTab('show')
+ .end()
+ .find('li:last a')
+ .bootstrapTab('show')
+
+ $(tabsHTML)
+ .find('li:first a')
+ .on('hidden.bs.tab', function () {
+ ok(true, 'hidden event fired')
+ start()
+ })
+ .bootstrapTab('show')
+ .end()
+ .find('li:last a')
+ .bootstrapTab('show')
+ })
+
+ test('should not fire hidden when hide is prevented', function () {
+ stop()
+
+ var tabsHTML = '<ul class="tabs">'
+ + '<li><a href="#home">Home</a></li>'
+ + '<li><a href="#profile">Profile</a></li>'
+ + '</ul>'
+
+ $(tabsHTML)
+ .find('li:first a')
+ .on('hide.bs.tab', function (e) {
+ e.preventDefault()
+ ok(true, 'hide event fired')
+ start()
+ })
+ .on('hidden.bs.tab', function () {
+ ok(false, 'hidden event fired')
+ })
+ .bootstrapTab('show')
+ .end()
+ .find('li:last a')
+ .bootstrapTab('show')
+ })
+
+ test('hide and hidden events contain correct relatedTarget', function () {
+ stop()
+
+ var tabsHTML = '<ul class="tabs">'
+ + '<li><a href="#home">Home</a></li>'
+ + '<li><a href="#profile">Profile</a></li>'
+ + '</ul>'
+
+ $(tabsHTML)
+ .find('li:first a')
+ .on('hide.bs.tab', function (e) {
+ equal(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
+ })
+ .on('hidden.bs.tab', function (e) {
+ equal(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
+ start()
+ })
+ .bootstrapTab('show')
+ .end()
+ .find('li:last a')
+ .bootstrapTab('show')
+ })
+
})