diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js
index 1cdfc7f90711..ef6ef74b9159 100644
--- a/js/tests/unit/affix.js
+++ b/js/tests/unit/affix.js
@@ -19,15 +19,18 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.affix, 'affix was set back to undefined (org value)')
+ strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $affix = $el.bootstrapAffix()
+ ok($affix instanceof $, 'returns jquery collection')
+ strictEqual($affix[0], $el[0], 'collection contains element')
})
test('should exit early if element is not visible', function () {
- var $affix = $('').bootstrapAffix()
+ var $affix = $('').bootstrapAffix()
$affix.data('bs.affix').checkPosition()
ok(!$affix.hasClass('affix'), 'affix class was not added')
})
@@ -35,8 +38,14 @@ $(function () {
test('should trigger affixed event after affix', function () {
stop()
- var template = $('
Please affix
And unaffix
')
- template.appendTo('body')
+ var templateHTML = '
'
+ + '
'
+ + '
Please affix
'
+ + '
And unaffix
'
+ + '
'
+ + '
'
+ + ''
+ $(templateHTML).appendTo(document.body)
$('#affixTarget').bootstrapAffix({
offset: $('#affixTarget ul').position()
@@ -44,19 +53,19 @@ $(function () {
$('#affixTarget')
.on('affix.bs.affix', function () {
- ok(true, 'affix event triggered')
+ ok(true, 'affix event fired')
}).on('affixed.bs.affix', function () {
- ok(true, 'affixed event triggered')
- $('#affixTarget').remove()
- $('#affixAfter').remove()
+ ok(true, 'affixed event fired')
+ $('#affixTarget, #affixAfter').remove()
start()
})
setTimeout(function () {
window.scrollTo(0, document.body.scrollHeight)
+
setTimeout(function () {
window.scroll(0, 0)
- }, 0)
+ }, 16) // for testing in a browser
}, 0)
})
})
diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js
index 31116cce25b0..52505c828d42 100644
--- a/js/tests/unit/alert.js
+++ b/js/tests/unit/alert.js
@@ -19,52 +19,52 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.alert, 'alert was set back to undefined (org value)')
+ strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapAlert()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $alert = $el.bootstrapAlert()
+ ok($alert instanceof $, 'returns jquery collection')
+ strictEqual($alert[0], $el[0], 'collection contains element')
})
test('should fade element out on clicking .close', function () {
- var alertHTML = '
Holy guacamole! Best check yo self, you\'re not looking too good.
' +
- '
'
- var alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
+ notEqual($('#qunit-fixture').find('.alert-message').length, 0, 'element added to dom')
- ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
+ $alert.find('.close').click()
- alert.find('.close').click()
-
- ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
+ equal($('#qunit-fixture').find('.alert-message').length, 0, 'element removed from dom')
})
test('should not fire closed when close is prevented', function () {
- $.support.transition = false
stop()
$('')
.on('close.bs.alert', function (e) {
e.preventDefault()
- ok(true)
+ ok(true, 'close event fired')
start()
})
.on('closed.bs.alert', function () {
- ok(false)
+ ok(false, 'closed event fired')
})
.bootstrapAlert('close')
})
diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js
index 671a93891d4e..bd431d5467ee 100644
--- a/js/tests/unit/button.js
+++ b/js/tests/unit/button.js
@@ -19,133 +19,133 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.button, 'button was set back to undefined (org value)')
+ strictEqual($.fn.button, undefined, 'button was set back to undefined (org value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapButton()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $button = $el.bootstrapButton()
+ ok($button instanceof $, 'returns jquery collection')
+ strictEqual($button[0], $el[0], 'collection contains element')
})
test('should return set state to loading', function () {
- var btn = $('')
- equal(btn.html(), 'mdo', 'btn text equals mdo')
- btn.bootstrapButton('loading')
- equal(btn.html(), 'fat', 'btn text equals fat')
+ var $btn = $('')
+ equal($btn.html(), 'mdo', 'btn text equals mdo')
+ $btn.bootstrapButton('loading')
+ equal($btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
- ok(btn.attr('disabled'), 'btn is disabled')
- ok(btn.hasClass('disabled'), 'btn has disabled class')
+ ok($btn[0].hasAttribute('disabled'), 'btn is disabled')
+ ok($btn.hasClass('disabled'), 'btn has disabled class')
start()
}, 0)
})
test('should return reset state', function () {
- var btn = $('')
- equal(btn.html(), 'mdo', 'btn text equals mdo')
- btn.bootstrapButton('loading')
- equal(btn.html(), 'fat', 'btn text equals fat')
+ var $btn = $('')
+ equal($btn.html(), 'mdo', 'btn text equals mdo')
+ $btn.bootstrapButton('loading')
+ equal($btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
- ok(btn.attr('disabled'), 'btn is disabled')
- ok(btn.hasClass('disabled'), 'btn has disabled class')
+ ok($btn[0].hasAttribute('disabled'), 'btn is disabled')
+ ok($btn.hasClass('disabled'), 'btn has disabled class')
start()
stop()
- btn.bootstrapButton('reset')
- equal(btn.html(), 'mdo', 'btn text equals mdo')
+ $btn.bootstrapButton('reset')
+ equal($btn.html(), 'mdo', 'btn text equals mdo')
setTimeout(function () {
- ok(!btn.attr('disabled'), 'btn is not disabled')
- ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
+ ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled')
+ ok(!$btn.hasClass('disabled'), 'btn does not have disabled class')
start()
}, 0)
}, 0)
})
test('should work with an empty string as reset state', function () {
- var btn = $('')
- equal(btn.html(), '', 'btn text equals ""')
- btn.bootstrapButton('loading')
- equal(btn.html(), 'fat', 'btn text equals fat')
+ var $btn = $('')
+ equal($btn.html(), '', 'btn text equals ""')
+ $btn.bootstrapButton('loading')
+ equal($btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
- ok(btn.attr('disabled'), 'btn is disabled')
- ok(btn.hasClass('disabled'), 'btn has disabled class')
+ ok($btn[0].hasAttribute('disabled'), 'btn is disabled')
+ ok($btn.hasClass('disabled'), 'btn has disabled class')
start()
stop()
- btn.bootstrapButton('reset')
- equal(btn.html(), '', 'btn text equals ""')
+ $btn.bootstrapButton('reset')
+ equal($btn.html(), '', 'btn text equals ""')
setTimeout(function () {
- ok(!btn.attr('disabled'), 'btn is not disabled')
- ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
+ ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled')
+ ok(!$btn.hasClass('disabled'), 'btn does not have disabled class')
start()
}, 0)
}, 0)
})
test('should toggle active', function () {
- var btn = $('')
- ok(!btn.hasClass('active'), 'btn does not have active class')
- btn.bootstrapButton('toggle')
- ok(btn.hasClass('active'), 'btn has class active')
+ var $btn = $('')
+ ok(!$btn.hasClass('active'), 'btn does not have active class')
+ $btn.bootstrapButton('toggle')
+ ok($btn.hasClass('active'), 'btn has class active')
})
test('should toggle active when btn children are clicked', function () {
- var btn = $('')
- var inner = $('')
- btn
- .append(inner)
- .appendTo($('#qunit-fixture'))
- ok(!btn.hasClass('active'), 'btn does not have active class')
- inner.click()
- ok(btn.hasClass('active'), 'btn has class active')
+ var $btn = $('')
+ var $inner = $('')
+ $btn
+ .append($inner)
+ .appendTo('#qunit-fixture')
+ ok(!$btn.hasClass('active'), 'btn does not have active class')
+ $inner.click()
+ ok($btn.hasClass('active'), 'btn has class active')
})
test('should toggle active when btn children are clicked within btn-group', function () {
- var btngroup = $('')
- var btn = $('')
- var inner = $('')
- btngroup
- .append(btn.append(inner))
- .appendTo($('#qunit-fixture'))
- ok(!btn.hasClass('active'), 'btn does not have active class')
- inner.click()
- ok(btn.hasClass('active'), 'btn has class active')
+ var $btngroup = $('')
+ var $btn = $('')
+ var $inner = $('')
+ $btngroup
+ .append($btn.append($inner))
+ .appendTo('#qunit-fixture')
+ ok(!$btn.hasClass('active'), 'btn does not have active class')
+ $inner.click()
+ ok($btn.hasClass('active'), 'btn has class active')
})
test('should check for closest matching toggle', function () {
- var group = '
' +
- '' +
- '' +
- '' +
- '
'
-
- group = $(group)
-
- var btn1 = $(group.children()[0])
- var btn2 = $(group.children()[1])
-
- group.appendTo($('#qunit-fixture'))
-
- ok(btn1.hasClass('active'), 'btn1 has active class')
- ok(btn1.find('input').prop('checked'), 'btn1 is checked')
- ok(!btn2.hasClass('active'), 'btn2 does not have active class')
- ok(!btn2.find('input').prop('checked'), 'btn2 is not checked')
- btn2.find('input').click()
- ok(!btn1.hasClass('active'), 'btn1 does not have active class')
- ok(!btn1.find('input').prop('checked'), 'btn1 is checked')
- ok(btn2.hasClass('active'), 'btn2 has active class')
- ok(btn2.find('input').prop('checked'), 'btn2 is checked')
-
- btn2.find('input').click() /* clicking an already checked radio should not un-check it */
- ok(!btn1.hasClass('active'), 'btn1 does not have active class')
- ok(!btn1.find('input').prop('checked'), 'btn1 is checked')
- ok(btn2.hasClass('active'), 'btn2 has active class')
- ok(btn2.find('input').prop('checked'), 'btn2 is checked')
+ var groupHTML = '
'
+ + ''
+ + ''
+ + ''
+ + '
'
+ var $group = $(groupHTML).appendTo('#qunit-fixture')
+
+ var $btn1 = $group.children().eq(0)
+ var $btn2 = $group.children().eq(1)
+
+ ok($btn1.hasClass('active'), 'btn1 has active class')
+ ok($btn1.find('input').prop('checked'), 'btn1 is checked')
+ ok(!$btn2.hasClass('active'), 'btn2 does not have active class')
+ ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked')
+ $btn2.find('input').click()
+ ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
+ ok(!$btn1.find('input').prop('checked'), 'btn1 is checked')
+ ok($btn2.hasClass('active'), 'btn2 has active class')
+ ok($btn2.find('input').prop('checked'), 'btn2 is checked')
+
+ $btn2.find('input').click() // clicking an already checked radio should not un-check it
+ ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
+ ok(!$btn1.find('input').prop('checked'), 'btn1 is checked')
+ ok($btn2.hasClass('active'), 'btn2 has active class')
+ ok($btn2.find('input').prop('checked'), 'btn2 is checked')
})
})
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js
index 474cfb40c721..51872c57b4a4 100644
--- a/js/tests/unit/carousel.js
+++ b/js/tests/unit/carousel.js
@@ -19,156 +19,358 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)')
+ strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapCarousel()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $carousel = $el.bootstrapCarousel()
+ ok($carousel instanceof $, 'returns jquery collection')
+ strictEqual($carousel[0], $el[0], 'collection contains element')
})
- test('should not fire slide when slide is prevented', function () {
- $.support.transition = false
+ test('should not fire slid when slide is prevented', function () {
stop()
$('')
.on('slide.bs.carousel', function (e) {
e.preventDefault()
- ok(true)
+ ok(true, 'slide event fired')
start()
})
.on('slid.bs.carousel', function () {
- ok(false)
+ ok(false, 'slid event fired')
})
.bootstrapCarousel('next')
})
test('should reset when slide is prevented', function () {
- var template = '
'
- var $carousel = $(template)
- $.support.transition = false
+ var carouselHTML = '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Second Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Third Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
'
- $.support.transition = false
+ var carouselHTML = '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
First Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Second Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Third Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ var $carousel = $(carouselHTML)
+
stop()
- $(template).on('slide.bs.carousel', function (e) {
- e.preventDefault()
- ok(e.direction)
- ok(e.direction === 'right' || e.direction === 'left')
- start()
- }).bootstrapCarousel('next')
+
+ $carousel
+ .one('slide.bs.carousel', function (e) {
+ ok(e.direction, 'direction present on next')
+ strictEqual(e.direction, 'left', 'direction is left on next')
+
+ $carousel
+ .one('slide.bs.carousel', function (e) {
+ ok(e.direction, 'direction present on prev')
+ strictEqual(e.direction, 'right', 'direction is right on prev')
+ start()
+ })
+ .bootstrapCarousel('prev')
+ })
+ .bootstrapCarousel('next')
})
test('should fire slid event with direction', function () {
- var template = '
{{_i}}First Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Second Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Third Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
'
- $.support.transition = false
+ var carouselHTML = '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
First Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Second Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Third Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ var $carousel = $(carouselHTML)
+
stop()
- $(template).on('slid.bs.carousel', function (e) {
- e.preventDefault()
- ok(e.direction)
- ok(e.direction === 'right' || e.direction === 'left')
- start()
- }).bootstrapCarousel('next')
+
+ $carousel
+ .one('slid.bs.carousel', function (e) {
+ ok(e.direction, 'direction present on next')
+ strictEqual(e.direction, 'left', 'direction is left on next')
+
+ $carousel
+ .one('slid.bs.carousel', function (e) {
+ ok(e.direction, 'direction present on prev')
+ strictEqual(e.direction, 'right', 'direction is right on prev')
+ start()
+ })
+ .bootstrapCarousel('prev')
+ })
+ .bootstrapCarousel('next')
})
test('should fire slide event with relatedTarget', function () {
- var template = '
{{_i}}First Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Second Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Third Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
'
- $.support.transition = false
+ var template = '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
First Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Second Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Third Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+
stop()
+
$(template)
.on('slide.bs.carousel', function (e) {
- e.preventDefault()
- ok(e.relatedTarget)
- ok($(e.relatedTarget).hasClass('item'))
+ ok(e.relatedTarget, 'relatedTarget present')
+ ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"')
start()
})
.bootstrapCarousel('next')
})
test('should fire slid event with relatedTarget', function () {
- var template = '
{{_i}}First Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Second Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Third Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
'
- $.support.transition = false
+ var template = '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
First Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Second Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Third Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+
stop()
+
$(template)
.on('slid.bs.carousel', function (e) {
- e.preventDefault()
- ok(e.relatedTarget)
- ok($(e.relatedTarget).hasClass('item'))
+ ok(e.relatedTarget, 'relatedTarget present')
+ ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"')
start()
})
.bootstrapCarousel('next')
})
- test('should set interval from data attribute', 4, function () {
- var template = $('
{{_i}}First Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Second Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
{{_i}}Third Thumbnail label{{/i}}
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.
')
- template.attr('data-interval', 1814)
+ test('should set interval from data attribute', function () {
+ var templateHTML = '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
First Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Second Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
+ + '
'
+ + '
'
+ + '
'
+ + ''
+ + '
'
+ + '
Third Thumbnail label
'
+ + '
Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec '
+ + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh '
+ + 'ultricies vehicula ut id elit.
'
- var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
-
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
+ test('should not open dropdown if target is disabled via attribute', function () {
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
+
+ ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
})
- test('should not open dropdown if target is disabled', function () {
- var dropdownHTML = '
'
- var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
-
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
+ test('should not open dropdown if target is disabled via class', function () {
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
+
+ ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
})
test('should add class open to menu if clicked', function () {
- var dropdownHTML = '
'
- var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
-
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
+
+ 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 () {
- var dropdownHTML = '
'
- var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
-
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
+
+ ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
})
- test('should remove open class if body clicked', function () {
- var dropdownHTML = '
'
- var dropdown = $(dropdownHTML)
- .appendTo('#qunit-fixture')
- .find('[data-toggle="dropdown"]')
- .bootstrapDropdown()
- .click()
-
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- $('body').click()
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
- dropdown.remove()
+ test('should remove "open" class if body is clicked', function () {
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+ .click()
+
+ ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
+ $(document.body).click()
+ ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed')
})
- test('should remove open class if body clicked, with multiple drop downs', function () {
- var dropdownHTML = '
'
- var dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
- var first = dropdowns.first()
- var last = dropdowns.last()
-
- ok(dropdowns.length == 2, 'Should be two dropdowns')
-
- first.click()
- ok(first.parents('.open').length == 1, 'open class added on click')
- ok($('#qunit-fixture .open').length == 1, 'only one object is open')
- $('body').click()
- ok($('#qunit-fixture .open').length === 0, 'open class removed')
-
- last.click()
- ok(last.parent('.open').length == 1, 'open class added on click')
- ok($('#qunit-fixture .open').length == 1, 'only one object is open')
- $('body').click()
- ok($('#qunit-fixture .open').length === 0, 'open class removed')
-
- $('#qunit-fixture').html('')
+ test('should remove "open" class if body is clicked, with multiple dropdowns', function () {
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
stop()
- dropdown
+ $dropdown
.parent('.dropdown')
.on('shown.bs.dropdown', function () {
- ok(true, 'show was called')
+ ok(true, 'shown was fired')
})
.on('hidden.bs.dropdown', function () {
- ok(true, 'hide was called')
+ ok(true, 'hidden was fired')
start()
})
- dropdown.click()
+ $dropdown.click()
$(document.body).click()
})
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index 7a0660ea2065..6c48ed44b4bb 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -4,8 +4,7 @@ $(function () {
module('modal plugin')
test('should be defined on jquery object', function () {
- var div = $('')
- ok(div.modal, 'modal method is defined')
+ ok($(document.body).modal, 'modal method is defined')
})
module('modal', {
@@ -20,13 +19,14 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.modal, 'modal was set back to undefined (orig value)')
+ strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)')
})
- test('should return element', function () {
- var div = $('')
- ok(div.bootstrapModal() == div, 'document.body returned')
- $('#modal-test').remove()
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $modal = $el.bootstrapModal()
+ ok($modal instanceof $, 'returns jquery collection')
+ strictEqual($modal[0], $el[0], 'collection contains element')
})
test('should expose defaults var for settings', function () {
@@ -35,11 +35,10 @@ $(function () {
test('should insert into dom when show method is called', function () {
stop()
- $.support.transition = false
- $('')
+
+ $('')
.on('shown.bs.modal', function () {
- ok($('#modal-test').length, 'modal inserted into dom')
- $(this).remove()
+ notEqual($('#modal-test').length, 0, 'modal inserted into dom')
start()
})
.bootstrapModal('show')
@@ -47,46 +46,41 @@ $(function () {
test('should fire show event', function () {
stop()
- $.support.transition = false
- $('')
+
+ $('')
.on('show.bs.modal', function () {
- ok(true, 'show was called')
- })
- .on('shown.bs.modal', function () {
- $(this).remove()
+ ok(true, 'show event fired')
start()
})
.bootstrapModal('show')
})
- test('should not fire shown when default prevented', function () {
+ test('should not fire shown when show was prevented', function () {
stop()
- $.support.transition = false
- $('')
+
+ $('')
.on('show.bs.modal', function (e) {
e.preventDefault()
- ok(true, 'show was called')
+ ok(true, 'show event fired')
start()
})
.on('shown.bs.modal', function () {
- ok(false, 'shown was called')
+ ok(false, 'shown event fired')
})
.bootstrapModal('show')
})
test('should hide modal when hide is called', function () {
stop()
- $.support.transition = false
- $('')
+ $('')
.on('shown.bs.modal', function () {
ok($('#modal-test').is(':visible'), 'modal visible')
- ok($('#modal-test').length, 'modal inserted into dom')
+ notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$(this).bootstrapModal('hide')
})
.on('hidden.bs.modal', function () {
ok(!$('#modal-test').is(':visible'), 'modal hidden')
- $('#modal-test').remove()
start()
})
.bootstrapModal('show')
@@ -94,17 +88,15 @@ $(function () {
test('should toggle when toggle is called', function () {
stop()
- $.support.transition = false
- var div = $('')
- div
+
+ $('')
.on('shown.bs.modal', function () {
ok($('#modal-test').is(':visible'), 'modal visible')
- ok($('#modal-test').length, 'modal inserted into dom')
- div.bootstrapModal('toggle')
+ notEqual($('#modal-test').length, 0, 'modal inserted into dom')
+ $(this).bootstrapModal('toggle')
})
.on('hidden.bs.modal', function () {
ok(!$('#modal-test').is(':visible'), 'modal hidden')
- div.remove()
start()
})
.bootstrapModal('toggle')
@@ -112,17 +104,15 @@ $(function () {
test('should remove from dom when click [data-dismiss="modal"]', function () {
stop()
- $.support.transition = false
- var div = $('
')
- div
+
+ $('
')
.on('shown.bs.modal', function () {
ok($('#modal-test').is(':visible'), 'modal visible')
- ok($('#modal-test').length, 'modal inserted into dom')
- div.find('.close').click()
+ notEqual($('#modal-test').length, 0, 'modal inserted into dom')
+ $(this).find('.close').click()
})
.on('hidden.bs.modal', function () {
ok(!$('#modal-test').is(':visible'), 'modal hidden')
- div.remove()
start()
})
.bootstrapModal('toggle')
@@ -130,16 +120,14 @@ $(function () {
test('should allow modal close with "backdrop:false"', function () {
stop()
- $.support.transition = false
- var div = $('
', { id: 'modal-test', 'data-backdrop': false })
- div
+
+ $('')
.on('shown.bs.modal', function () {
ok($('#modal-test').is(':visible'), 'modal visible')
- div.bootstrapModal('hide')
+ $(this).bootstrapModal('hide')
})
.on('hidden.bs.modal', function () {
ok(!$('#modal-test').is(':visible'), 'modal hidden')
- div.remove()
start()
})
.bootstrapModal('show')
@@ -147,18 +135,16 @@ $(function () {
test('should close modal when clicking outside of modal-content', function () {
stop()
- $.support.transition = false
- var div = $('
')
- div
+
+ $('
')
.on('shown.bs.modal', function () {
- ok($('#modal-test').length, 'modal insterted into dom')
+ notEqual($('#modal-test').length, 0, 'modal insterted into dom')
$('.contents').click()
ok($('#modal-test').is(':visible'), 'modal visible')
$('#modal-test').mousedown()
})
.on('hidden.bs.modal', function () {
ok(!$('#modal-test').is(':visible'), 'modal hidden')
- div.remove()
start()
})
.bootstrapModal('show')
@@ -204,19 +190,17 @@ $(function () {
test('should trigger hide event once when clicking outside of modal-content', function () {
stop()
- $.support.transition = false
var triggered
- var div = $('
')
- div
+ $('
')
.on('shown.bs.modal', function () {
triggered = 0
$('#modal-test').mousedown()
})
.on('hide.bs.modal', function () {
triggered += 1
- ok(triggered === 1, 'modal hide triggered once')
+ strictEqual(triggered, 1, 'modal hide triggered once')
start()
})
.bootstrapModal('show')
@@ -224,34 +208,31 @@ $(function () {
test('should close reopened modal with [data-dismiss="modal"] click', function () {
stop()
- $.support.transition = false
- var div = $('
')
- div
+
+ $('
')
.on('shown.bs.modal', function () {
$('#close').click()
ok(!$('#modal-test').is(':visible'), 'modal hidden')
})
.one('hidden.bs.modal', function () {
- div.one('hidden.bs.modal', function () {
- start()
- }).bootstrapModal('show')
+ $(this)
+ .one('hidden.bs.modal', function () {
+ start()
+ })
+ .bootstrapModal('show')
})
.bootstrapModal('show')
-
- div.remove()
})
test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function () {
stop()
- $.support.transition = false
- var toggleBtn = $('').appendTo('#qunit-fixture')
- var div = $('
')
- div
+
+ var $toggleBtn = $('').appendTo('#qunit-fixture')
+
+ $('
')
.on('hidden.bs.modal', function () {
- window.setTimeout(function () { // give the focus restoration callback a chance to run
- equal(document.activeElement, toggleBtn[0], 'toggling element is once again focused')
- div.remove()
- toggleBtn.remove()
+ setTimeout(function () {
+ ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused')
start()
}, 0)
})
@@ -259,29 +240,26 @@ $(function () {
$('#close').click()
})
.appendTo('#qunit-fixture')
- toggleBtn.click()
+
+ $toggleBtn.click()
})
test('should not restore focus to toggling element if the associated show event gets prevented', function () {
stop()
- $.support.transition = false
- var toggleBtn = $('').appendTo('#qunit-fixture')
- var otherBtn = $('').appendTo('#qunit-fixture')
- var div = $('
')
- div
+ var $toggleBtn = $('').appendTo('#qunit-fixture')
+ var $otherBtn = $('').appendTo('#qunit-fixture')
+
+ $('
')
.one('show.bs.modal', function (e) {
e.preventDefault()
- otherBtn.focus()
- window.setTimeout(function () { // give the focus event from the previous line a chance to run
- div.bootstrapModal('show')
- }, 0)
+ $otherBtn.focus()
+ setTimeout($.proxy(function () {
+ $(this).bootstrapModal('show')
+ }, this), 0)
})
.on('hidden.bs.modal', function () {
- window.setTimeout(function () { // give the focus restoration callback a chance to run (except it shouldn't run in this case)
- equal(document.activeElement, otherBtn[0], 'show was prevented, so focus should not have been restored to toggling element')
- div.remove()
- toggleBtn.remove()
- otherBtn.remove()
+ setTimeout(function () {
+ ok($(document.activeElement).is($otherBtn), 'focus returned to toggling element')
start()
}, 0)
})
@@ -289,6 +267,7 @@ $(function () {
$('#close').click()
})
.appendTo('#qunit-fixture')
- toggleBtn.click()
+
+ $toggleBtn.click()
})
})
diff --git a/js/tests/unit/phantom.js b/js/tests/unit/phantom.js
index b5f0c67a67ad..ea7455cfc35a 100644
--- a/js/tests/unit/phantom.js
+++ b/js/tests/unit/phantom.js
@@ -2,7 +2,7 @@
* grunt-contrib-qunit
* http://gruntjs.com/
*
- * Copyright (c) 2013 "Cowboy" Ben Alman, contributors
+ * Copyright (c) 2014 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
@@ -21,48 +21,52 @@
}
// These methods connect QUnit to PhantomJS.
- QUnit.log = function (obj) {
+ QUnit.log(function (obj) {
// What is this I don’t even
if (obj.message === '[object Object], undefined:undefined') { return }
+
// Parse some stuff before sending it.
- var actual = QUnit.jsDump.parse(obj.actual)
- var expected = QUnit.jsDump.parse(obj.expected)
+ var actual
+ var expected
+ if (!obj.result) {
+ // Dumping large objects can be very slow, and the dump isn't used for
+ // passing tests, so only dump if the test failed.
+ actual = QUnit.jsDump.parse(obj.actual)
+ expected = QUnit.jsDump.parse(obj.expected)
+ }
// Send it.
sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source)
- }
+ })
- QUnit.testStart = function (obj) {
+ QUnit.testStart(function (obj) {
sendMessage('qunit.testStart', obj.name)
- }
+ })
- QUnit.testDone = function (obj) {
- sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total)
- }
+ QUnit.testDone(function (obj) {
+ sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.duration)
+ })
- QUnit.moduleStart = function (obj) {
+ QUnit.moduleStart(function (obj) {
sendMessage('qunit.moduleStart', obj.name)
- }
+ })
- QUnit.begin = function () {
- sendMessage('qunit.begin')
- console.log('Starting test suite')
- console.log('================================================\n')
- }
-
- QUnit.moduleDone = function (opts) {
- if (opts.failed === 0) {
- console.log('\r\u2714 All tests passed in "' + opts.name + '" module')
+ QUnit.moduleDone(function (obj) {
+ if (obj.failed === 0) {
+ console.log('\r\u2714 All tests passed in "' + obj.name + '" module')
} else {
- console.log('\u2716 ' + opts.failed + ' tests failed in "' + opts.name + '" module')
+ console.log('\u2716 ' + obj.failed + ' tests failed in "' + obj.name + '" module')
}
- sendMessage('qunit.moduleDone', opts.name, opts.failed, opts.passed, opts.total)
- }
+ sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total)
+ })
- QUnit.done = function (opts) {
- console.log('\n================================================')
- console.log('Tests completed in ' + opts.runtime + ' milliseconds')
- console.log(opts.passed + ' tests of ' + opts.total + ' passed, ' + opts.failed + ' failed.')
- sendMessage('qunit.done', opts.failed, opts.passed, opts.total, opts.runtime)
- }
+ QUnit.begin(function () {
+ sendMessage('qunit.begin')
+ console.log('\n\nStarting test suite')
+ console.log('================================================\n')
+ })
+
+ QUnit.done(function (obj) {
+ sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime)
+ })
}())
diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js
index 16f94e14384f..5cb4cafddc22 100644
--- a/js/tests/unit/popover.js
+++ b/js/tests/unit/popover.js
@@ -4,8 +4,7 @@ $(function () {
module('popover plugin')
test('should be defined on jquery object', function () {
- var div = $('')
- ok(div.popover, 'popover method is defined')
+ ok($(document.body).popover, 'popover method is defined')
})
module('popover', {
@@ -20,46 +19,44 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.popover, 'popover was set back to undefined (org value)')
+ strictEqual($.fn.popover, undefined, 'popover was set back to undefined (org value)')
})
- test('should return element', function () {
- var div = $('')
- ok(div.bootstrapPopover() == div, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $popover = $el.bootstrapPopover()
+ ok($popover instanceof $, 'returns jquery collection')
+ strictEqual($popover[0], $el[0], 'collection contains element')
})
test('should render popover element', function () {
- $.support.transition = false
- var popover = $('@mdo')
+ var $popover = $('@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover removed')
+ notEqual($('.popover').length, 0, 'popover was inserted')
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover removed')
})
test('should store popover instance in popover data object', function () {
- $.support.transition = false
- var popover = $('@mdo')
- .bootstrapPopover()
+ var $popover = $('@mdo').bootstrapPopover()
- ok(!!popover.data('bs.popover'), 'popover instance exists')
+ ok($popover.data('bs.popover'), 'popover instance exists')
})
test('should store popover trigger in popover instance data object', function () {
- $.support.transition = false
- var popover = $('@ResentedHook')
+ var $popover = $('@ResentedHook')
.appendTo('#qunit-fixture')
.bootstrapPopover()
- popover.bootstrapPopover('show')
- ok(!!$('.popover').data('bs.popover'), 'popover trigger stored in instance data')
- $('#qunit-fixture').empty()
+
+ $popover.bootstrapPopover('show')
+
+ ok($('.popover').data('bs.popover'), 'popover trigger stored in instance data')
})
test('should get title and content from options', function () {
- $.support.transition = false
- var popover = $('@fat')
+ var $popover = $('@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: function () {
@@ -70,23 +67,20 @@ $(function () {
}
})
- popover.bootstrapPopover('show')
+ $popover.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ notEqual($('.popover').length, 0, 'popover was inserted')
equal($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
equal($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
- $('#qunit-fixture').empty()
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
})
test('should not duplicate HTML object', function () {
- $.support.transition = false
+ var $div = $('').html('loves writing tests (╯°□°)╯︵ ┻━┻')
- var $div = $('
').html('loves writing tests (╯°□°)╯︵ ┻━┻')
-
- var popover = $('@fat')
+ var $popover = $('@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
content: function () {
@@ -94,42 +88,38 @@ $(function () {
}
})
- popover.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ $popover.bootstrapPopover('show')
+ notEqual($('.popover').length, 0, 'popover was inserted')
equal($('.popover .popover-content').html(), $div, 'content correctly inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
- popover.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ $popover.bootstrapPopover('show')
+ notEqual($('.popover').length, 0, 'popover was inserted')
equal($('.popover .popover-content').html(), $div, 'content correctly inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
- $('#qunit-fixture').empty()
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
})
test('should get title and content from attributes', function () {
- $.support.transition = false
- var popover = $('@mdo')
+ var $popover = $('@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover()
.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ notEqual($('.popover').length, 0, 'popover was inserted')
equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
equal($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
- $('#qunit-fixture').empty()
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
})
- test('should get title and content from attributes #2', function () {
- $.support.transition = false
- var popover = $('@mdo')
+ test('should get title and content from attributes ignoring options passed via js', function () {
+ var $popover = $('@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'ignored title option',
@@ -137,48 +127,50 @@ $(function () {
})
.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ notEqual($('.popover').length, 0, 'popover was inserted')
equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
equal($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
- $('#qunit-fixture').empty()
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
})
- test('should respect custom classes', function () {
- $.support.transition = false
- var popover = $('@fat')
+ test('should respect custom template', function () {
+ var $popover = $('@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'Test',
content: 'Test',
- template: '
'
+ template: '
'
})
- popover.bootstrapPopover('show')
+ $popover.bootstrapPopover('show')
- ok($('.popover').length, 'popover was inserted')
+ notEqual($('.popover').length, 0, 'popover was inserted')
ok($('.popover').hasClass('foobar'), 'custom class is present')
- popover.bootstrapPopover('hide')
- ok(!$('.popover').length, 'popover was removed')
- $('#qunit-fixture').empty()
+ $popover.bootstrapPopover('hide')
+ equal($('.popover').length, 0, 'popover was removed')
})
test('should destroy popover', function () {
- var popover = $('').bootstrapPopover({
- trigger: 'hover'
- }).on('click.foo', function () {})
- ok(popover.data('bs.popover'), 'popover has data')
- ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event')
- ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover has extra click.foo event')
- popover.bootstrapPopover('show')
- popover.bootstrapPopover('destroy')
- ok(!popover.hasClass('in'), 'popover is hidden')
- ok(!popover.data('popover'), 'popover does not have data')
- ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover still has click.foo')
- ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events')
+ var $popover = $('')
+ .bootstrapPopover({
+ trigger: 'hover'
+ })
+ .on('click.foo', $.noop)
+
+ ok($popover.data('bs.popover'), 'popover has data')
+ ok($._data($popover[0], 'events').mouseover && $._data($popover[0], 'events').mouseout, 'popover has hover event')
+ equal($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover has extra click.foo event')
+
+ $popover.bootstrapPopover('show')
+ $popover.bootstrapPopover('destroy')
+
+ ok(!$popover.hasClass('in'), 'popover is hidden')
+ ok(!$popover.data('popover'), 'popover does not have data')
+ equal($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover still has click.foo')
+ ok(!$._data($popover[0], 'events').mouseover && !$._data($popover[0], 'events').mouseout, 'popover does not have any events')
})
})
diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js
index 2ec51fc2438e..3eefac85d273 100644
--- a/js/tests/unit/scrollspy.js
+++ b/js/tests/unit/scrollspy.js
@@ -19,99 +19,106 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.scrollspy, 'scrollspy was set back to undefined (org value)')
+ strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $scrollspy = $el.bootstrapScrollspy()
+ ok($scrollspy instanceof $, 'returns jquery collection')
+ strictEqual($scrollspy[0], $el[0], 'collection contains element')
})
- test('should switch active class on scroll', function () {
- var sectionHTML = ''
- $(sectionHTML).append('#qunit-fixture')
- var topbarHTML = '
'
var $topbar = $(topbarHTML).bootstrapScrollspy()
- $(sectionHTML).append('#qunit-fixture')
ok($topbar.find('.active', true))
})
- asyncTest('should only switch active class on current target', function () {
- expect(1);
- var sectionHTML = '
'
var $section = $(sectionHTML).appendTo('#qunit-fixture')
- var $scrollSpy = $section
+
+ var $scrollspy = $section
.show()
.find('#scrollspy-example')
.bootstrapScrollspy({ target: '#ss-target' })
- $scrollSpy.on('scroll.bs.scrollspy', function () {
- ok($section.hasClass('active'), 'Active class still on root node')
+ $scrollspy.on('scroll.bs.scrollspy', function () {
+ ok($section.hasClass('active'), '"active" class still on root node')
start()
})
- $scrollSpy.scrollTop(350);
+
+ $scrollspy.scrollTop(350)
})
- asyncTest('middle navigation option correctly selected when large offset is used', function () {
- expect(3);
- var sectionHTML = '' +
- '' +
- '
' +
- '' +
- '' +
- '' +
- '
'
+ test('middle navigation option correctly selected when large offset is used', function () {
+ stop()
+
+ var sectionHTML = ''
+ + ''
+ + '
'
+ + ''
+ + ''
+ + ''
+ + '
'
var $section = $(sectionHTML).appendTo('#qunit-fixture')
- var $scrollSpy = $section
+ var $scrollspy = $section
.show()
.filter('#content')
- $scrollSpy.bootstrapScrollspy({ target: '#navigation', offset: $scrollSpy.position().top })
- $scrollSpy.on('scroll.bs.scrollspy', function () {
- 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')
- ok(!$section.find('#three-link').parent().hasClass('active'), 'Active class not on last section')
+ $scrollspy.bootstrapScrollspy({ target: '#navigation', offset: $scrollspy.position().top })
+
+ $scrollspy.on('scroll.bs.scrollspy', function () {
+ 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')
+ ok(!$section.find('#three-link').parent().hasClass('active'), '"active" class not on last section')
start()
})
- $scrollSpy.scrollTop(550);
+
+ $scrollspy.scrollTop(550)
})
})
diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js
index 0c49feeaf8d3..8e50614ecce7 100644
--- a/js/tests/unit/tab.js
+++ b/js/tests/unit/tab.js
@@ -19,20 +19,23 @@ $(function () {
})
test('should provide no conflict', function () {
- ok(!$.fn.tab, 'tab was set back to undefined (org value)')
+ strictEqual($.fn.tab, undefined, 'tab was set back to undefined (org value)')
})
- test('should return element', function () {
- ok($(document.body).bootstrapTab()[0] == document.body, 'document.body returned')
+ test('should return jquery collection containing the element', function () {
+ var $el = $('')
+ var $tab = $el.bootstrapTab()
+ ok($tab instanceof $, 'returns jquery collection')
+ strictEqual($tab[0], $el[0], 'collection contains element')
})
test('should activate element by tab id', function () {
- var tabsHTML = '