diff options
Diffstat (limited to 'js/tests/unit/carousel.js')
| -rw-r--r-- | js/tests/unit/carousel.js | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 9f6f9ccf2..2044b1408 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -1,13 +1,13 @@ $(function () { 'use strict'; - module('carousel plugin') + QUnit.module('carousel plugin') - test('should be defined on jQuery object', function () { - ok($(document.body).carousel, 'carousel method is defined') + QUnit.test('should be defined on jQuery object', function (assert) { + assert.ok($(document.body).carousel, 'carousel method is defined') }) - module('carousel', { + QUnit.module('carousel', { setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapCarousel = $.fn.carousel.noConflict() @@ -18,32 +18,32 @@ $(function () { } }) - test('should provide no conflict', function () { - strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)') + QUnit.test('should provide no conflict', function (assert) { + assert.strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig 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 $carousel = $el.bootstrapCarousel() - ok($carousel instanceof $, 'returns jquery collection') - strictEqual($carousel[0], $el[0], 'collection contains element') + assert.ok($carousel instanceof $, 'returns jquery collection') + assert.strictEqual($carousel[0], $el[0], 'collection contains element') }) - test('should not fire slid when slide is prevented', function (assert) { + QUnit.test('should not fire slid when slide is prevented', function (assert) { var done = assert.async() $('<div class="carousel"/>') .on('slide.bs.carousel', function (e) { e.preventDefault() - ok(true, 'slide event fired') + assert.ok(true, 'slide event fired') done() }) .on('slid.bs.carousel', function () { - ok(false, 'slid event fired') + assert.ok(false, 'slid event fired') }) .bootstrapCarousel('next') }) - test('should reset when slide is prevented', function (assert) { + QUnit.test('should reset when slide is prevented', function (assert) { var carouselHTML = '<div id="carousel-example-generic" class="carousel slide">' + '<ol class="carousel-indicators">' + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' @@ -71,24 +71,24 @@ $(function () { .one('slide.bs.carousel', function (e) { e.preventDefault() setTimeout(function () { - ok($carousel.find('.item:eq(0)').is('.active'), 'first item still active') - ok($carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') + assert.ok($carousel.find('.item:eq(0)').is('.active'), 'first item still active') + assert.ok($carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') $carousel.bootstrapCarousel('next') }, 0) }) .one('slid.bs.carousel', function () { setTimeout(function () { - ok(!$carousel.find('.item:eq(0)').is('.active'), 'first item still active') - ok(!$carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') - ok($carousel.find('.item:eq(1)').is('.active'), 'second item active') - ok($carousel.find('.carousel-indicators li:eq(1)').is('.active'), 'second indicator active') + assert.ok(!$carousel.find('.item:eq(0)').is('.active'), 'first item still active') + assert.ok(!$carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') + assert.ok($carousel.find('.item:eq(1)').is('.active'), 'second item active') + assert.ok($carousel.find('.carousel-indicators li:eq(1)').is('.active'), 'second indicator active') done() }, 0) }) .bootstrapCarousel('next') }) - test('should fire slide event with direction', function (assert) { + QUnit.test('should fire slide event with direction', function (assert) { var carouselHTML = '<div id="myCarousel" class="carousel slide">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -128,13 +128,13 @@ $(function () { $carousel .one('slide.bs.carousel', function (e) { - ok(e.direction, 'direction present on next') - strictEqual(e.direction, 'left', 'direction is left on next') + assert.ok(e.direction, 'direction present on next') + assert.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') + assert.ok(e.direction, 'direction present on prev') + assert.strictEqual(e.direction, 'right', 'direction is right on prev') done() }) .bootstrapCarousel('prev') @@ -142,7 +142,7 @@ $(function () { .bootstrapCarousel('next') }) - test('should fire slid event with direction', function (assert) { + QUnit.test('should fire slid event with direction', function (assert) { var carouselHTML = '<div id="myCarousel" class="carousel slide">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -182,13 +182,13 @@ $(function () { $carousel .one('slid.bs.carousel', function (e) { - ok(e.direction, 'direction present on next') - strictEqual(e.direction, 'left', 'direction is left on next') + assert.ok(e.direction, 'direction present on next') + assert.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') + assert.ok(e.direction, 'direction present on prev') + assert.strictEqual(e.direction, 'right', 'direction is right on prev') done() }) .bootstrapCarousel('prev') @@ -196,7 +196,7 @@ $(function () { .bootstrapCarousel('next') }) - test('should fire slide event with relatedTarget', function (assert) { + QUnit.test('should fire slide event with relatedTarget', function (assert) { var template = '<div id="myCarousel" class="carousel slide">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -235,14 +235,14 @@ $(function () { $(template) .on('slide.bs.carousel', function (e) { - ok(e.relatedTarget, 'relatedTarget present') - ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"') + assert.ok(e.relatedTarget, 'relatedTarget present') + assert.ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"') done() }) .bootstrapCarousel('next') }) - test('should fire slid event with relatedTarget', function (assert) { + QUnit.test('should fire slid event with relatedTarget', function (assert) { var template = '<div id="myCarousel" class="carousel slide">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -281,14 +281,14 @@ $(function () { $(template) .on('slid.bs.carousel', function (e) { - ok(e.relatedTarget, 'relatedTarget present') - ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"') + assert.ok(e.relatedTarget, 'relatedTarget present') + assert.ok($(e.relatedTarget).hasClass('item'), 'relatedTarget has class "item"') done() }) .bootstrapCarousel('next') }) - test('should set interval from data attribute', function () { + QUnit.test('should set interval from data attribute', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel slide">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -327,29 +327,29 @@ $(function () { $carousel.appendTo('body') $('[data-slide]').first().click() - equal($carousel.data('bs.carousel').options.interval, 1814) + assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814) $carousel.remove() $carousel.appendTo('body').attr('data-modal', 'foobar') $('[data-slide]').first().click() - equal($carousel.data('bs.carousel').options.interval, 1814, 'even if there is an data-modal attribute set') + assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814, 'even if there is an data-modal attribute set') $carousel.remove() $carousel.appendTo('body') $('[data-slide]').first().click() $carousel.attr('data-interval', 1860) $('[data-slide]').first().click() - equal($carousel.data('bs.carousel').options.interval, 1814, 'attributes should be read only on initialization') + assert.strictEqual($carousel.data('bs.carousel').options.interval, 1814, 'attributes should be read only on initialization') $carousel.remove() $carousel.attr('data-interval', false) $carousel.appendTo('body') $carousel.bootstrapCarousel(1) - strictEqual($carousel.data('bs.carousel').options.interval, false, 'data attribute has higher priority than default options') + assert.strictEqual($carousel.data('bs.carousel').options.interval, false, 'data attribute has higher priority than default options') $carousel.remove() }) - test('should skip over non-items when using item indices', function () { + QUnit.test('should skip over non-items when using item indices', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -367,14 +367,14 @@ $(function () { $template.bootstrapCarousel() - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') $template.bootstrapCarousel(1) - strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') }) - test('should skip over non-items when using next/prev methods', function () { + QUnit.test('should skip over non-items when using next/prev methods', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' + '<div class="carousel-inner">' + '<div class="item active">' @@ -392,14 +392,14 @@ $(function () { $template.bootstrapCarousel() - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') $template.bootstrapCarousel('next') - strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') }) - test('should go to previous item if left arrow key is pressed', function () { + QUnit.test('should go to previous item if left arrow key is pressed', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + '<div class="carousel-inner">' + '<div id="first" class="item">' @@ -417,14 +417,14 @@ $(function () { $template.bootstrapCarousel() - strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') $template.trigger($.Event('keydown', { which: 37 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') }) - test('should go to next item if right arrow key is pressed', function () { + QUnit.test('should go to next item if right arrow key is pressed', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + '<div class="carousel-inner">' + '<div id="first" class="item active">' @@ -442,14 +442,14 @@ $(function () { $template.bootstrapCarousel() - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') $template.trigger($.Event('keydown', { which: 39 })) - strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') }) - test('should support disabling the keyboard navigation', function () { + QUnit.test('should support disabling the keyboard navigation', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-keyboard="false">' + '<div class="carousel-inner">' + '<div id="first" class="item active">' @@ -467,18 +467,18 @@ $(function () { $template.bootstrapCarousel() - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') $template.trigger($.Event('keydown', { which: 39 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press') $template.trigger($.Event('keydown', { which: 37 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press') }) - test('should ignore keyboard events within <input>s and <textarea>s', function () { + QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) { var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + '<div class="carousel-inner">' + '<div id="first" class="item active">' @@ -498,29 +498,29 @@ $(function () { var $input = $template.find('#in-put') var $textarea = $template.find('#text-area') - strictEqual($input.length, 1, 'found <input>') - strictEqual($textarea.length, 1, 'found <textarea>') + assert.strictEqual($input.length, 1, 'found <input>') + assert.strictEqual($textarea.length, 1, 'found <textarea>') $template.bootstrapCarousel() - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') $input.trigger($.Event('keydown', { which: 39 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <input>') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <input>') $input.trigger($.Event('keydown', { which: 37 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <input>') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <input>') $textarea.trigger($.Event('keydown', { which: 39 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <textarea>') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <textarea>') $textarea.trigger($.Event('keydown', { which: 37 })) - strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>') + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>') }) - test('should only add mouseenter and mouseleave listeners when not on mobile', function () { + QUnit.test('should only add mouseenter and mouseleave listeners when not on mobile', function (assert) { var isMobile = 'ontouchstart' in document.documentElement var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">' + '<div class="carousel-inner">' @@ -538,11 +538,11 @@ $(function () { var $template = $(templateHTML).bootstrapCarousel() $.each(['mouseover', 'mouseout'], function (i, type) { - strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events') + assert.strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events') }) }) - test('should wrap around from end to start when wrap option is true', function (assert) { + QUnit.test('should wrap around from end to start when wrap option is true', function (assert) { var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' + '<ol class="carousel-indicators">' + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' @@ -570,13 +570,13 @@ $(function () { $carousel .one('slid.bs.carousel', function () { - strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') + assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') $carousel .one('slid.bs.carousel', function () { - strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') + assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') $carousel .one('slid.bs.carousel', function () { - strictEqual(getActiveId(), 'one', 'carousel wrapped around and slid from 3rd to 1st slide') + assert.strictEqual(getActiveId(), 'one', 'carousel wrapped around and slid from 3rd to 1st slide') done() }) .bootstrapCarousel('next') @@ -586,7 +586,7 @@ $(function () { .bootstrapCarousel('next') }) - test('should wrap around from start to end when wrap option is true', function (assert) { + QUnit.test('should wrap around from start to end when wrap option is true', function (assert) { var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' + '<ol class="carousel-indicators">' + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' @@ -613,13 +613,13 @@ $(function () { $carousel .on('slid.bs.carousel', function () { - strictEqual($carousel.find('.item.active').attr('id'), 'three', 'carousel wrapped around and slid from 1st to 3rd slide') + assert.strictEqual($carousel.find('.item.active').attr('id'), 'three', 'carousel wrapped around and slid from 1st to 3rd slide') done() }) .bootstrapCarousel('prev') }) - test('should stay at the end when the next method is called and wrap is false', function (assert) { + QUnit.test('should stay at the end when the next method is called and wrap is false', function (assert) { var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' + '<ol class="carousel-indicators">' + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' @@ -647,16 +647,16 @@ $(function () { $carousel .one('slid.bs.carousel', function () { - strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') + assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') $carousel .one('slid.bs.carousel', function () { - strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') + assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') $carousel .one('slid.bs.carousel', function () { - ok(false, 'carousel slid when it should not have slid') + assert.ok(false, 'carousel slid when it should not have slid') }) .bootstrapCarousel('next') - strictEqual(getActiveId(), 'three', 'carousel did not wrap around and stayed on 3rd slide') + assert.strictEqual(getActiveId(), 'three', 'carousel did not wrap around and stayed on 3rd slide') done() }) .bootstrapCarousel('next') @@ -664,7 +664,7 @@ $(function () { .bootstrapCarousel('next') }) - test('should stay at the start when the prev method is called and wrap is false', function () { + QUnit.test('should stay at the start when the prev method is called and wrap is false', function (assert) { var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' + '<ol class="carousel-indicators">' + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' @@ -689,9 +689,9 @@ $(function () { $carousel .on('slid.bs.carousel', function () { - ok(false, 'carousel slid when it should not have slid') + assert.ok(false, 'carousel slid when it should not have slid') }) .bootstrapCarousel('prev') - strictEqual($carousel.find('.item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide') + assert.strictEqual($carousel.find('.item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide') }) }) |
