Commit ecd469ec authored by Chris Rebert's avatar Chris Rebert

Merge pull request #15893 from twbs/qunit-modern

Modernize QUnit usage by avoiding usage of global functions
parents feda77f1 9c75c855
$(function () { $(function () {
'use strict'; 'use strict';
module('affix plugin') QUnit.module('affix plugin')
test('should be defined on jquery object', function () { QUnit.test('should be defined on jquery object', function (assert) {
ok($(document.body).affix, 'affix method is defined') assert.ok($(document.body).affix, 'affix method is defined')
}) })
module('affix', { QUnit.module('affix', {
setup: function () { setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapAffix = $.fn.affix.noConflict() $.fn.bootstrapAffix = $.fn.affix.noConflict()
...@@ -18,24 +18,24 @@ $(function () { ...@@ -18,24 +18,24 @@ $(function () {
} }
}) })
test('should provide no conflict', function () { QUnit.test('should provide no conflict', function (assert) {
strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)') assert.strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)')
}) })
test('should return jquery collection containing the element', function () { QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>') var $el = $('<div/>')
var $affix = $el.bootstrapAffix() var $affix = $el.bootstrapAffix()
ok($affix instanceof $, 'returns jquery collection') assert.ok($affix instanceof $, 'returns jquery collection')
strictEqual($affix[0], $el[0], 'collection contains element') assert.strictEqual($affix[0], $el[0], 'collection contains element')
}) })
test('should exit early if element is not visible', function () { QUnit.test('should exit early if element is not visible', function (assert) {
var $affix = $('<div style="display: none"/>').bootstrapAffix() var $affix = $('<div style="display: none"/>').bootstrapAffix()
$affix.data('bs.affix').checkPosition() $affix.data('bs.affix').checkPosition()
ok(!$affix.hasClass('affix'), 'affix class was not added') assert.ok(!$affix.hasClass('affix'), 'affix class was not added')
}) })
test('should trigger affixed event after affix', function (assert) { QUnit.test('should trigger affixed event after affix', function (assert) {
var done = assert.async() var done = assert.async()
var templateHTML = '<div id="affixTarget">' var templateHTML = '<div id="affixTarget">'
...@@ -53,9 +53,9 @@ $(function () { ...@@ -53,9 +53,9 @@ $(function () {
$('#affixTarget') $('#affixTarget')
.on('affix.bs.affix', function () { .on('affix.bs.affix', function () {
ok(true, 'affix event fired') assert.ok(true, 'affix event fired')
}).on('affixed.bs.affix', function () { }).on('affixed.bs.affix', function () {
ok(true, 'affixed event fired') assert.ok(true, 'affixed event fired')
$('#affixTarget, #affixAfter').remove() $('#affixTarget, #affixAfter').remove()
done() done()
}) })
...@@ -69,7 +69,7 @@ $(function () { ...@@ -69,7 +69,7 @@ $(function () {
}, 0) }, 0)
}) })
test('should affix-top when scrolling up to offset when parent has padding', function (assert) { QUnit.test('should affix-top when scrolling up to offset when parent has padding', function (assert) {
var done = assert.async() var done = assert.async()
var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">' var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">'
...@@ -85,7 +85,7 @@ $(function () { ...@@ -85,7 +85,7 @@ $(function () {
offset: { top: 120, bottom: 0 } offset: { top: 120, bottom: 0 }
}) })
.on('affixed-top.bs.affix', function () { .on('affixed-top.bs.affix', function () {
ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied') assert.ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied')
$('#padding-offset').remove() $('#padding-offset').remove()
done() done()
}) })
......
$(function () { $(function () {
'use strict'; 'use strict';
module('alert plugin') QUnit.module('alert plugin')
test('should be defined on jquery object', function () { QUnit.test('should be defined on jquery object', function (assert) {
ok($(document.body).alert, 'alert method is defined') assert.ok($(document.body).alert, 'alert method is defined')
}) })
module('alert', { QUnit.module('alert', {
setup: function () { setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapAlert = $.fn.alert.noConflict() $.fn.bootstrapAlert = $.fn.alert.noConflict()
...@@ -18,18 +18,18 @@ $(function () { ...@@ -18,18 +18,18 @@ $(function () {
} }
}) })
test('should provide no conflict', function () { QUnit.test('should provide no conflict', function (assert) {
strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)') assert.strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)')
}) })
test('should return jquery collection containing the element', function () { QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>') var $el = $('<div/>')
var $alert = $el.bootstrapAlert() var $alert = $el.bootstrapAlert()
ok($alert instanceof $, 'returns jquery collection') assert.ok($alert instanceof $, 'returns jquery collection')
strictEqual($alert[0], $el[0], 'collection contains element') assert.strictEqual($alert[0], $el[0], 'collection contains element')
}) })
test('should fade element out on clicking .close', function () { QUnit.test('should fade element out on clicking .close', function (assert) {
var alertHTML = '<div class="alert alert-danger fade in">' var alertHTML = '<div class="alert alert-danger fade in">'
+ '<a class="close" href="#" data-dismiss="alert">×</a>' + '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
...@@ -38,33 +38,33 @@ $(function () { ...@@ -38,33 +38,33 @@ $(function () {
$alert.find('.close').click() $alert.find('.close').click()
equal($alert.hasClass('in'), false, 'remove .in class on .close click') assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click')
}) })
test('should remove element when clicking .close', function () { QUnit.test('should remove element when clicking .close', function (assert) {
var alertHTML = '<div class="alert alert-danger fade in">' var alertHTML = '<div class="alert alert-danger fade in">'
+ '<a class="close" href="#" data-dismiss="alert">×</a>' + '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
+ '</div>' + '</div>'
var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom') assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')
$alert.find('.close').click() $alert.find('.close').click()
equal($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom') assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
}) })
test('should not fire closed when close is prevented', function (assert) { QUnit.test('should not fire closed when close is prevented', function (assert) {
var done = assert.async() var done = assert.async()
$('<div class="alert"/>') $('<div class="alert"/>')
.on('close.bs.alert', function (e) { .on('close.bs.alert', function (e) {
e.preventDefault() e.preventDefault()
ok(true, 'close event fired') assert.ok(true, 'close event fired')
done() done()
}) })
.on('closed.bs.alert', function () { .on('closed.bs.alert', function () {
ok(false, 'closed event fired') assert.ok(false, 'closed event fired')
}) })
.bootstrapAlert('close') .bootstrapAlert('close')
}) })
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
$(function () { $(function () {
'use strict'; 'use strict';
module('dropdowns plugin') QUnit.module('dropdowns plugin')
test('should be defined on jquery object', function () { QUnit.test('should be defined on jquery object', function (assert) {
ok($(document.body).dropdown, 'dropdown method is defined') assert.ok($(document.body).dropdown, 'dropdown method is defined')
}) })
module('dropdowns', { QUnit.module('dropdowns', {
setup: function () { setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapDropdown = $.fn.dropdown.noConflict() $.fn.bootstrapDropdown = $.fn.dropdown.noConflict()
...@@ -18,18 +18,18 @@ $(function () { ...@@ -18,18 +18,18 @@ $(function () {
} }
}) })
test('should provide no conflict', function () { QUnit.test('should provide no conflict', function (assert) {
strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)') assert.strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)')
}) })
test('should return jquery collection containing the element', function () { QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>') var $el = $('<div/>')
var $dropdown = $el.bootstrapDropdown() var $dropdown = $el.bootstrapDropdown()
ok($dropdown instanceof $, 'returns jquery collection') assert.ok($dropdown instanceof $, 'returns jquery collection')
strictEqual($dropdown[0], $el[0], 'collection contains element') assert.strictEqual($dropdown[0], $el[0], 'collection contains element')
}) })
test('should not open dropdown if target is disabled via attribute', function () { QUnit.test('should not open dropdown if target is disabled via attribute', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>'
...@@ -43,10 +43,10 @@ $(function () { ...@@ -43,10 +43,10 @@ $(function () {
+ '</ul>' + '</ul>'
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
}) })
test('should not open dropdown if target is disabled via class', function () { QUnit.test('should not open dropdown if target is disabled via class', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>'
...@@ -60,10 +60,10 @@ $(function () { ...@@ -60,10 +60,10 @@ $(function () {
+ '</ul>' + '</ul>'
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
}) })
test('should add class open to menu if clicked', function () { QUnit.test('should add class open to menu if clicked', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
...@@ -77,10 +77,10 @@ $(function () { ...@@ -77,10 +77,10 @@ $(function () {
+ '</ul>' + '</ul>'
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
}) })
test('should test if element has a # before assuming it\'s a selector', function () { QUnit.test('should test if element has a # before assuming it\'s a selector', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
...@@ -94,11 +94,11 @@ $(function () { ...@@ -94,11 +94,11 @@ $(function () {
+ '</ul>' + '</ul>'
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
}) })
test('should remove "open" class if body is clicked', function () { QUnit.test('should remove "open" class if body is clicked', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
...@@ -116,12 +116,12 @@ $(function () { ...@@ -116,12 +116,12 @@ $(function () {
.bootstrapDropdown() .bootstrapDropdown()
.click() .click()
ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
$(document.body).click() $(document.body).click()
ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed') assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed')
}) })
test('should remove "open" class if body is clicked, with multiple dropdowns', function () { QUnit.test('should remove "open" class if body is clicked, with multiple dropdowns', function (assert) {
var dropdownHTML = '<ul class="nav">' var dropdownHTML = '<ul class="nav">'
+ '<li><a href="#menu1">Menu 1</a></li>' + '<li><a href="#menu1">Menu 1</a></li>'
+ '<li class="dropdown" id="testmenu">' + '<li class="dropdown" id="testmenu">'
...@@ -142,22 +142,22 @@ $(function () { ...@@ -142,22 +142,22 @@ $(function () {
var $first = $dropdowns.first() var $first = $dropdowns.first()
var $last = $dropdowns.last() var $last = $dropdowns.last()
strictEqual($dropdowns.length, 2, 'two dropdowns') assert.strictEqual($dropdowns.length, 2, 'two dropdowns')
$first.click() $first.click()
strictEqual($first.parents('.open').length, 1, '"open" class added on click') assert.strictEqual($first.parents('.open').length, 1, '"open" class added on click')
strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open')
$(document.body).click() $(document.body).click()
strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed')
$last.click() $last.click()
strictEqual($last.parent('.open').length, 1, '"open" class added on click') assert.strictEqual($last.parent('.open').length, 1, '"open" class added on click')
strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open')
$(document.body).click() $(document.body).click()
strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed')
}) })
test('should fire show and hide event', function (assert) { QUnit.test('should fire show and hide event', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
...@@ -179,10 +179,10 @@ $(function () { ...@@ -179,10 +179,10 @@ $(function () {
$dropdown $dropdown
.parent('.dropdown') .parent('.dropdown')
.on('show.bs.dropdown', function () { .on('show.bs.dropdown', function () {
ok(true, 'show was fired') assert.ok(true, 'show was fired')
}) })
.on('hide.bs.dropdown', function () { .on('hide.bs.dropdown', function () {
ok(true, 'hide was fired') assert.ok(true, 'hide was fired')
done() done()
}) })
...@@ -191,7 +191,7 @@ $(function () { ...@@ -191,7 +191,7 @@ $(function () {
}) })
test('should fire shown and hidden event', function (assert) { QUnit.test('should fire shown and hidden event', function (assert) {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
...@@ -213,10 +213,10 @@ $(function () { ...@@ -213,10 +213,10 @@ $(function () {
$dropdown $dropdown
.parent('.dropdown') .parent('.dropdown')
.on('shown.bs.dropdown', function () { .on('shown.bs.dropdown', function () {
ok(true, 'shown was fired') assert.ok(true, 'shown was fired')
}) })
.on('hidden.bs.dropdown', function () { .on('hidden.bs.dropdown', function () {
ok(true, 'hidden was fired') assert.ok(true, 'hidden was fired')
done() done()
}) })
...@@ -224,7 +224,7 @@ $(function () { ...@@ -224,7 +224,7 @@ $(function () {
$(document.body).click() $(document.body).click()
}) })
test('should ignore keyboard events within <input>s and <textarea>s', function (assert) { QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) {
var done = assert.async() var done = assert.async()
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
...@@ -251,13 +251,13 @@ $(function () { ...@@ -251,13 +251,13 @@ $(function () {
$dropdown $dropdown
.parent('.dropdown') .parent('.dropdown')
.on('shown.bs.dropdown', function () { .on('shown.bs.dropdown', function () {
ok(true, 'shown was fired') assert.ok(true, 'shown was fired')
$input.focus().trigger($.Event('keydown', { which: 38 })) $input.focus().trigger($.Event('keydown', { which: 38 }))
ok($(document.activeElement).is($input), 'input still focused') assert.ok($(document.activeElement).is($input), 'input still focused')
$textarea.focus().trigger($.Event('keydown', { which: 38 })) $textarea.focus().trigger($.Event('keydown', { which: 38 }))
ok($(document.activeElement).is($textarea), 'textarea still focused') assert.ok($(document.activeElement).is($textarea), 'textarea still focused')
done() done()
}) })
......
This diff is collapsed.
This diff is collapsed.
$(function () { $(function () {
'use strict'; 'use strict';
module('scrollspy plugin') QUnit.module('scrollspy plugin')
test('should be defined on jquery object', function () { QUnit.test('should be defined on jquery object', function (assert) {
ok($(document.body).scrollspy, 'scrollspy method is defined') assert.ok($(document.body).scrollspy, 'scrollspy method is defined')
}) })
module('scrollspy', { QUnit.module('scrollspy', {
setup: function () { setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapScrollspy = $.fn.scrollspy.noConflict() $.fn.bootstrapScrollspy = $.fn.scrollspy.noConflict()
...@@ -18,18 +18,18 @@ $(function () { ...@@ -18,18 +18,18 @@ $(function () {
} }
}) })
test('should provide no conflict', function () { QUnit.test('should provide no conflict', function (assert) {
strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)') assert.strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)')
}) })
test('should return jquery collection containing the element', function () { QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>') var $el = $('<div/>')
var $scrollspy = $el.bootstrapScrollspy() var $scrollspy = $el.bootstrapScrollspy()
ok($scrollspy instanceof $, 'returns jquery collection') assert.ok($scrollspy instanceof $, 'returns jquery collection')
strictEqual($scrollspy[0], $el[0], 'collection contains element') assert.strictEqual($scrollspy[0], $el[0], 'collection contains element')
}) })
test('should only switch "active" class on current target', function (assert) { QUnit.test('should only switch "active" class on current target', function (assert) {
var done = assert.async() var done = assert.async()
var sectionHTML = '<div id="root" class="active">' var sectionHTML = '<div id="root" class="active">'
...@@ -66,14 +66,14 @@ $(function () { ...@@ -66,14 +66,14 @@ $(function () {
.bootstrapScrollspy({ target: '#ss-target' }) .bootstrapScrollspy({ target: '#ss-target' })
$scrollspy.on('scroll.bs.scrollspy', function () { $scrollspy.on('scroll.bs.scrollspy', function () {
ok($section.hasClass('active'), '"active" class still on root node') assert.ok($section.hasClass('active'), '"active" class still on root node')
done() done()
}) })
$scrollspy.scrollTop(350) $scrollspy.scrollTop(350)
}) })
test('should correctly select middle navigation option when large offset is used', function (assert) { QUnit.test('should correctly select middle navigation option when large offset is used', function (assert) {
var done = assert.async() var done = assert.async()
var sectionHTML = '<div id="header" style="height: 500px;"></div>' var sectionHTML = '<div id="header" style="height: 500px;"></div>'
...@@ -97,16 +97,16 @@ $(function () { ...@@ -97,16 +97,16 @@ $(function () {
$scrollspy.bootstrapScrollspy({ target: '#navigation', offset: $scrollspy.position().top }) $scrollspy.bootstrapScrollspy({ target: '#navigation', offset: $scrollspy.position().top })
$scrollspy.on('scroll.bs.scrollspy', function () { $scrollspy.on('scroll.bs.scrollspy', function () {
ok(!$section.find('#one-link').parent().hasClass('active'), '"active" class removed from first section') assert.ok(!$section.find('#one-link').parent().hasClass('active'), '"active" class removed from first section')
ok($section.find('#two-link').parent().hasClass('active'), '"active" class on middle section') assert.ok($section.find('#two-link').parent().hasClass('active'), '"active" class on middle section')
ok(!$section.find('#three-link').parent().hasClass('active'), '"active" class not on last section') assert.ok(!$section.find('#three-link').parent().hasClass('active'), '"active" class not on last section')
done() done()
}) })
$scrollspy.scrollTop(550) $scrollspy.scrollTop(550)
}) })
test('should add the active class to the correct element', function (assert) { QUnit.test('should add the active class to the correct element', function (assert) {
var navbarHtml = var navbarHtml =
'<nav class="navbar">' '<nav class="navbar">'
+ '<ul class="nav">' + '<ul class="nav">'
...@@ -130,7 +130,7 @@ $(function () { ...@@ -130,7 +130,7 @@ $(function () {
var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top)
var done = assert.async() var done = assert.async()
$content.one('scroll', function () { $content.one('scroll', function () {
ok($(element).hasClass('active'), 'target:' + target + ', element' + element) assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element)
done() done()
deferred.resolve() deferred.resolve()
}) })
...@@ -142,7 +142,7 @@ $(function () { ...@@ -142,7 +142,7 @@ $(function () {
.then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') })
}) })
test('should clear selection if above the first section', function (assert) { QUnit.test('should clear selection if above the first section', function (assert) {
var done = assert.async() var done = assert.async()
var sectionHTML = '<div id="header" style="height: 500px;"></div>' var sectionHTML = '<div id="header" style="height: 500px;"></div>'
...@@ -170,12 +170,12 @@ $(function () { ...@@ -170,12 +170,12 @@ $(function () {
offset: $scrollspy.position().top offset: $scrollspy.position().top
}) })
.one('scroll.bs.scrollspy', function () { .one('scroll.bs.scrollspy', function () {
strictEqual($('.active').length, 1, '"active" class on only one element present') assert.strictEqual($('.active').length, 1, '"active" class on only one element present')
strictEqual($('.active').has('#two-link').length, 1, '"active" class on second section') assert.strictEqual($('.active').has('#two-link').length, 1, '"active" class on second section')
$scrollspy $scrollspy
.one('scroll.bs.scrollspy', function () { .one('scroll.bs.scrollspy', function () {
strictEqual($('.active').length, 0, 'selection cleared') assert.strictEqual($('.active').length, 0, 'selection cleared')
done() done()
}) })
.scrollTop(0) .scrollTop(0)
......
$(function () { $(function () {
'use strict'; 'use strict';
module('tabs plugin') QUnit.module('tabs plugin')
test('should be defined on jquery object', function () { QUnit.test('should be defined on jquery object', function (assert) {
ok($(document.body).tab, 'tabs method is defined') assert.ok($(document.body).tab, 'tabs method is defined')
}) })
module('tabs', { QUnit.module('tabs', {
setup: function () { setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapTab = $.fn.tab.noConflict() $.fn.bootstrapTab = $.fn.tab.noConflict()
...@@ -18,18 +18,18 @@ $(function () { ...@@ -18,18 +18,18 @@ $(function () {
} }
}) })
test('should provide no conflict', function () { QUnit.test('should provide no conflict', function (assert) {
strictEqual($.fn.tab, undefined, 'tab was set back to undefined (org value)') assert.strictEqual($.fn.tab, undefined, 'tab was set back to undefined (org value)')
}) })
test('should return jquery collection containing the element', function () { QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>') var $el = $('<div/>')
var $tab = $el.bootstrapTab() var $tab = $el.bootstrapTab()
ok($tab instanceof $, 'returns jquery collection') assert.ok($tab instanceof $, 'returns jquery collection')
strictEqual($tab[0], $el[0], 'collection contains element') assert.strictEqual($tab[0], $el[0], 'collection contains element')
}) })
test('should activate element by tab id', function () { QUnit.test('should activate element by tab id', function (assert) {
var tabsHTML = '<ul class="tabs">' var tabsHTML = '<ul class="tabs">'
+ '<li><a href="#home">Home</a></li>' + '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>' + '<li><a href="#profile">Profile</a></li>'
...@@ -38,13 +38,13 @@ $(function () { ...@@ -38,13 +38,13 @@ $(function () {
$('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture') $('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture')
$(tabsHTML).find('li:last a').bootstrapTab('show') $(tabsHTML).find('li:last a').bootstrapTab('show')
equal($('#qunit-fixture').find('.active').attr('id'), 'profile') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(tabsHTML).find('li:first a').bootstrapTab('show') $(tabsHTML).find('li:first a').bootstrapTab('show')
equal($('#qunit-fixture').find('.active').attr('id'), 'home') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
}) })
test('should activate element by tab id', function () { QUnit.test('should activate element by tab id', function (assert) {
var pillsHTML = '<ul class="pills">' var pillsHTML = '<ul class="pills">'
+ '<li><a href="#home">Home</a></li>' + '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>' + '<li><a href="#profile">Profile</a></li>'
...@@ -53,28 +53,28 @@ $(function () { ...@@ -53,28 +53,28 @@ $(function () {
$('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture') $('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture')
$(pillsHTML).find('li:last a').bootstrapTab('show') $(pillsHTML).find('li:last a').bootstrapTab('show')
equal($('#qunit-fixture').find('.active').attr('id'), 'profile') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(pillsHTML).find('li:first a').bootstrapTab('show') $(pillsHTML).find('li:first a').bootstrapTab('show')
equal($('#qunit-fixture').find('.active').attr('id'), 'home') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
}) })
test('should not fire shown when show is prevented', function (assert) { QUnit.test('should not fire shown when show is prevented', function (assert) {
var done = assert.async() var done = assert.async()
$('<div class="tab"/>') $('<div class="tab"/>')
.on('show.bs.tab', function (e) { .on('show.bs.tab', function (e) {
e.preventDefault() e.preventDefault()
ok(true, 'show event fired') assert.ok(true, 'show event fired')
done() done()
}) })
.on('shown.bs.tab', function () { .on('shown.bs.tab', function () {
ok(false, 'shown event fired') assert.ok(false, 'shown event fired')
}) })
.bootstrapTab('show') .bootstrapTab('show')
}) })
test('show and shown events should reference correct relatedTarget', function (assert) { QUnit.test('show and shown events should reference correct relatedTarget', function (assert) {
var done = assert.async() var done = assert.async()
var dropHTML = '<ul class="drop">' var dropHTML = '<ul class="drop">'
...@@ -92,16 +92,16 @@ $(function () { ...@@ -92,16 +92,16 @@ $(function () {
.end() .end()
.find('ul > li:last a') .find('ul > li:last a')
.on('show.bs.tab', function (e) { .on('show.bs.tab', function (e) {
equal(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget') assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
}) })
.on('shown.bs.tab', function (e) { .on('shown.bs.tab', function (e) {
equal(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget') assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
done() done()
}) })
.bootstrapTab('show') .bootstrapTab('show')
}) })
test('should fire hide and hidden events', function (assert) { QUnit.test('should fire hide and hidden events', function (assert) {
var done = assert.async() var done = assert.async()
var tabsHTML = '<ul class="tabs">' var tabsHTML = '<ul class="tabs">'
...@@ -112,7 +112,7 @@ $(function () { ...@@ -112,7 +112,7 @@ $(function () {
$(tabsHTML) $(tabsHTML)
.find('li:first a') .find('li:first a')
.on('hide.bs.tab', function () { .on('hide.bs.tab', function () {
ok(true, 'hide event fired') assert.ok(true, 'hide event fired')
}) })
.bootstrapTab('show') .bootstrapTab('show')
.end() .end()
...@@ -122,7 +122,7 @@ $(function () { ...@@ -122,7 +122,7 @@ $(function () {
$(tabsHTML) $(tabsHTML)
.find('li:first a') .find('li:first a')
.on('hidden.bs.tab', function () { .on('hidden.bs.tab', function () {
ok(true, 'hidden event fired') assert.ok(true, 'hidden event fired')
done() done()
}) })
.bootstrapTab('show') .bootstrapTab('show')
...@@ -131,7 +131,7 @@ $(function () { ...@@ -131,7 +131,7 @@ $(function () {
.bootstrapTab('show') .bootstrapTab('show')
}) })
test('should not fire hidden when hide is prevented', function (assert) { QUnit.test('should not fire hidden when hide is prevented', function (assert) {
var done = assert.async() var done = assert.async()
var tabsHTML = '<ul class="tabs">' var tabsHTML = '<ul class="tabs">'
...@@ -143,11 +143,11 @@ $(function () { ...@@ -143,11 +143,11 @@ $(function () {
.find('li:first a') .find('li:first a')
.on('hide.bs.tab', function (e) { .on('hide.bs.tab', function (e) {
e.preventDefault() e.preventDefault()
ok(true, 'hide event fired') assert.ok(true, 'hide event fired')
done() done()
}) })
.on('hidden.bs.tab', function () { .on('hidden.bs.tab', function () {
ok(false, 'hidden event fired') assert.ok(false, 'hidden event fired')
}) })
.bootstrapTab('show') .bootstrapTab('show')
.end() .end()
...@@ -155,7 +155,7 @@ $(function () { ...@@ -155,7 +155,7 @@ $(function () {
.bootstrapTab('show') .bootstrapTab('show')
}) })
test('hide and hidden events contain correct relatedTarget', function (assert) { QUnit.test('hide and hidden events contain correct relatedTarget', function (assert) {
var done = assert.async() var done = assert.async()
var tabsHTML = '<ul class="tabs">' var tabsHTML = '<ul class="tabs">'
...@@ -166,10 +166,10 @@ $(function () { ...@@ -166,10 +166,10 @@ $(function () {
$(tabsHTML) $(tabsHTML)
.find('li:first a') .find('li:first a')
.on('hide.bs.tab', function (e) { .on('hide.bs.tab', function (e) {
equal(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget') assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
}) })
.on('hidden.bs.tab', function (e) { .on('hidden.bs.tab', function (e) {
equal(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget') assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
done() done()
}) })
.bootstrapTab('show') .bootstrapTab('show')
...@@ -178,7 +178,7 @@ $(function () { ...@@ -178,7 +178,7 @@ $(function () {
.bootstrapTab('show') .bootstrapTab('show')
}) })
test('selected tab should have aria-expanded', function () { QUnit.test('selected tab should have aria-expanded', function (assert) {
var tabsHTML = '<ul class="nav nav-tabs">' var tabsHTML = '<ul class="nav nav-tabs">'
+ '<li class="active"><a href="#home" toggle="tab" aria-expanded="true">Home</a></li>' + '<li class="active"><a href="#home" toggle="tab" aria-expanded="true">Home</a></li>'
+ '<li><a href="#profile" toggle="tab" aria-expanded="false">Profile</a></li>' + '<li><a href="#profile" toggle="tab" aria-expanded="false">Profile</a></li>'
...@@ -186,20 +186,20 @@ $(function () { ...@@ -186,20 +186,20 @@ $(function () {
var $tabs = $(tabsHTML).appendTo('#qunit-fixture') var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
$tabs.find('li:first a').bootstrapTab('show') $tabs.find('li:first a').bootstrapTab('show')
equal($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true')
equal($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false')
$tabs.find('li:last a').click() $tabs.find('li:last a').click()
equal($tabs.find('.active a').attr('aria-expanded'), 'true', 'after click, shown tab has aria-expanded = true') assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after click, shown tab has aria-expanded = true')
equal($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after click, hidden tab has aria-expanded = false') assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after click, hidden tab has aria-expanded = false')
$tabs.find('li:first a').bootstrapTab('show') $tabs.find('li:first a').bootstrapTab('show')
equal($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true')
equal($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false')
$tabs.find('li:first a').click() $tabs.find('li:first a').click()
equal($tabs.find('.active a').attr('aria-expanded'), 'true', 'after second show event, shown tab still has aria-expanded = true') assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after second show event, shown tab still has aria-expanded = true')
equal($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false') assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false')
}) })
}) })
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment