diff --git a/js/tests/index.html b/js/tests/index.html index 363ebe599adc..1c025cf761b4 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -13,23 +13,22 @@ @@ -70,7 +75,7 @@ -
+
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).bootstrapAlert() + var alertHTML = '
' + + '×' + + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + + '
' + var $alert = $(alertHTML).bootstrapAlert() - alert.find('.close').click() + $alert.find('.close').click() - ok(!alert.hasClass('in'), 'remove .in class on .close click') + equal($alert.hasClass('in'), false, 'remove .in class on .close click') }) test('should remove element when clicking .close', function () { - $.support.transition = false + var alertHTML = '
' + + '×' + + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + + '
' + var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() - 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 = $('') - 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() $('