From 7c19fee3f1f3a371445981cf7e88a3af92f3b602 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 23 Feb 2015 21:55:07 -0800 Subject: JS unit tests: use modern QUnit assert object everywhere --- js/tests/unit/tooltip.js | 294 +++++++++++++++++++++++------------------------ 1 file changed, 147 insertions(+), 147 deletions(-) (limited to 'js/tests/unit/tooltip.js') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index b734218b9..32913397b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -3,8 +3,8 @@ $(function () { module('tooltip plugin') - test('should be defined on jquery object', function () { - ok($(document.body).tooltip, 'tooltip method is defined') + test('should be defined on jquery object', function (assert) { + assert.ok($(document.body).tooltip, 'tooltip method is defined') }) module('tooltip', { @@ -18,32 +18,32 @@ $(function () { } }) - test('should provide no conflict', function () { - strictEqual($.fn.tooltip, undefined, 'tooltip was set back to undefined (org value)') + test('should provide no conflict', function (assert) { + assert.strictEqual($.fn.tooltip, undefined, 'tooltip was set back to undefined (org value)') }) - test('should return jquery collection containing the element', function () { + test('should return jquery collection containing the element', function (assert) { var $el = $('
') var $tooltip = $el.bootstrapTooltip() - ok($tooltip instanceof $, 'returns jquery collection') - strictEqual($tooltip[0], $el[0], 'collection contains element') + assert.ok($tooltip instanceof $, 'returns jquery collection') + assert.strictEqual($tooltip[0], $el[0], 'collection contains element') }) - test('should expose default settings', function () { - ok($.fn.bootstrapTooltip.Constructor.DEFAULTS, 'defaults is defined') + test('should expose default settings', function (assert) { + assert.ok($.fn.bootstrapTooltip.Constructor.DEFAULTS, 'defaults is defined') }) - test('should empty title attribute', function () { + test('should empty title attribute', function (assert) { var $trigger = $('').bootstrapTooltip() - strictEqual($trigger.attr('title'), '', 'title attribute was emptied') + assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied') }) - test('should add data attribute for referencing original title', function () { + test('should add data attribute for referencing original title', function (assert) { var $trigger = $('').bootstrapTooltip() - strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') + assert.strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') }) - test('should add aria-describedby to the trigger on show', function () { + test('should add aria-describedby to the trigger on show', function (assert) { var $trigger = $('') .bootstrapTooltip() .appendTo('#qunit-fixture') @@ -51,68 +51,68 @@ $(function () { var id = $('.tooltip').attr('id') - strictEqual($('#' + id).length, 1, 'has a unique id') - strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match') - ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') + assert.strictEqual($('#' + id).length, 1, 'has a unique id') + assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match') + assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') }) - test('should remove aria-describedby from trigger on hide', function () { + test('should remove aria-describedby from trigger on hide', function (assert) { var $trigger = $('') .bootstrapTooltip() .appendTo('#qunit-fixture') $trigger.bootstrapTooltip('show') - ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') + assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') $trigger.bootstrapTooltip('hide') - ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby') + assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby') }) - test('should assign a unique id tooltip element', function () { + test('should assign a unique id tooltip element', function (assert) { $('') .appendTo('#qunit-fixture') .bootstrapTooltip('show') var id = $('.tooltip').attr('id') - strictEqual($('#' + id).length, 1, 'tooltip has unique id') - strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix') + assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id') + assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix') }) - test('should place tooltips relative to placement option', function () { + test('should place tooltips relative to placement option', function (assert) { var $tooltip = $('') .appendTo('#qunit-fixture') .bootstrapTooltip({ placement: 'bottom' }) $tooltip.bootstrapTooltip('show') - ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') $tooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'tooltip removed') + assert.equal($('.tooltip').length, 0, 'tooltip removed') }) - test('should allow html entities', function () { + test('should allow html entities', function (assert) { var $tooltip = $('') .appendTo('#qunit-fixture') .bootstrapTooltip({ html: true }) $tooltip.bootstrapTooltip('show') - notEqual($('.tooltip b').length, 0, 'b tag was inserted') + assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted') $tooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'tooltip removed') + assert.equal($('.tooltip').length, 0, 'tooltip removed') }) - test('should respect custom classes', function () { + test('should respect custom classes', function (assert) { var $tooltip = $('') .appendTo('#qunit-fixture') .bootstrapTooltip({ template: '
' }) $tooltip.bootstrapTooltip('show') - ok($('.tooltip').hasClass('some-class'), 'custom class is present') + assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present') $tooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'tooltip removed') + assert.equal($('.tooltip').length, 0, 'tooltip removed') }) test('should fire show event', function (assert) { @@ -120,7 +120,7 @@ $(function () { $('
') .on('show.bs.tooltip', function () { - ok(true, 'show event fired') + assert.ok(true, 'show event fired') done() }) .bootstrapTooltip('show') @@ -132,7 +132,7 @@ $(function () { $('
') .appendTo('#qunit-fixture') .on('shown.bs.tooltip', function () { - ok(true, 'shown was called') + assert.ok(true, 'shown was called') done() }) .bootstrapTooltip('show') @@ -144,11 +144,11 @@ $(function () { $('
') .on('show.bs.tooltip', function (e) { e.preventDefault() - ok(true, 'show event fired') + assert.ok(true, 'show event fired') done() }) .on('shown.bs.tooltip', function () { - ok(false, 'shown event fired') + assert.ok(false, 'shown event fired') }) .bootstrapTooltip('show') }) @@ -162,7 +162,7 @@ $(function () { $(this).bootstrapTooltip('hide') }) .on('hide.bs.tooltip', function () { - ok(true, 'hide event fired') + assert.ok(true, 'hide event fired') done() }) .bootstrapTooltip('show') @@ -177,7 +177,7 @@ $(function () { $(this).bootstrapTooltip('hide') }) .on('hidden.bs.tooltip', function () { - ok(true, 'hidden event fired') + assert.ok(true, 'hidden event fired') done() }) .bootstrapTooltip('show') @@ -193,34 +193,34 @@ $(function () { }) .on('hide.bs.tooltip', function (e) { e.preventDefault() - ok(true, 'hide event fired') + assert.ok(true, 'hide event fired') done() }) .on('hidden.bs.tooltip', function () { - ok(false, 'hidden event fired') + assert.ok(false, 'hidden event fired') }) .bootstrapTooltip('show') }) - test('should destroy tooltip', function () { + test('should destroy tooltip', function (assert) { var $tooltip = $('
') .bootstrapTooltip() .on('click.foo', function () {}) - ok($tooltip.data('bs.tooltip'), 'tooltip has data') - ok($._data($tooltip[0], 'events').mouseover && $._data($tooltip[0], 'events').mouseout, 'tooltip has hover events') - equal($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip has extra click.foo event') + assert.ok($tooltip.data('bs.tooltip'), 'tooltip has data') + assert.ok($._data($tooltip[0], 'events').mouseover && $._data($tooltip[0], 'events').mouseout, 'tooltip has hover events') + assert.equal($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip has extra click.foo event') $tooltip.bootstrapTooltip('show') $tooltip.bootstrapTooltip('destroy') - ok(!$tooltip.hasClass('in'), 'tooltip is hidden') - ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data') - equal($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo') - ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events') + assert.ok(!$tooltip.hasClass('in'), 'tooltip is hidden') + assert.ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data') + assert.equal($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo') + assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events') }) - test('should show tooltip with delegate selector on click', function () { + test('should show tooltip with delegate selector on click', function (assert) { var $div = $('
') .appendTo('#qunit-fixture') .bootstrapTooltip({ @@ -229,45 +229,45 @@ $(function () { }) $div.find('a').click() - ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') + assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') $div.find('a').click() - equal($('.tooltip').length, 0, 'tooltip was removed from dom') + assert.equal($('.tooltip').length, 0, 'tooltip was removed from dom') }) - test('should show tooltip when toggle is called', function () { + test('should show tooltip when toggle is called', function (assert) { $('') .appendTo('#qunit-fixture') .bootstrapTooltip({ trigger: 'manual' }) .bootstrapTooltip('toggle') - ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') + assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') }) - test('should hide previously shown tooltip when toggle is called on tooltip', function () { + test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) { $('@ResentedHook') .appendTo('#qunit-fixture') .bootstrapTooltip({ trigger: 'manual' }) .bootstrapTooltip('show') $('.tooltip').bootstrapTooltip('toggle') - ok($('.tooltip').not('.fade.in'), 'tooltip was faded out') + assert.ok($('.tooltip').not('.fade.in'), 'tooltip was faded out') }) - test('should place tooltips inside body when container is body', function () { + test('should place tooltips inside body when container is body', function (assert) { var $tooltip = $('') .appendTo('#qunit-fixture') .bootstrapTooltip({ container: 'body' }) .bootstrapTooltip('show') - notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body') - equal($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent') + assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body') + assert.equal($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent') $tooltip.bootstrapTooltip('hide') - equal($('body > .tooltip').length, 0, 'tooltip was removed from dom') + assert.equal($('body > .tooltip').length, 0, 'tooltip was removed from dom') }) - test('should add position class before positioning so that position-specific styles are taken into account', function () { + test('should add position class before positioning so that position-specific styles are taken into account', function (assert) { var styles = '') var $container = $('
') .css({ @@ -353,36 +353,36 @@ $(function () { .bootstrapTooltip({ placement: 'auto' }) $topTooltip.bootstrapTooltip('show') - ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') + assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') $topTooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'top positioned tooltip removed from dom') + assert.equal($('.tooltip').length, 0, 'top positioned tooltip removed from dom') var $rightTooltip = $('
Right Dynamic Tooltip
') .appendTo($container) .bootstrapTooltip({ placement: 'right auto' }) $rightTooltip.bootstrapTooltip('show') - ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') + assert.ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') $rightTooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'right positioned tooltip removed from dom') + assert.equal($('.tooltip').length, 0, 'right positioned tooltip removed from dom') var $leftTooltip = $('
Left Dynamic Tooltip
') .appendTo($container) .bootstrapTooltip({ placement: 'auto left' }) $leftTooltip.bootstrapTooltip('show') - ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') + assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') $leftTooltip.bootstrapTooltip('hide') - equal($('.tooltip').length, 0, 'left positioned tooltip removed from dom') + assert.equal($('.tooltip').length, 0, 'left positioned tooltip removed from dom') $container.remove() $style.remove() }) - test('should position tip on top if viewport has enough space and placement is "auto top"', function () { + test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) { var styles = '') var $container = $('
') .css({ @@ -382,7 +382,7 @@ $(function () { $style.remove() }) - test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) { + QUnit.test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) { var styles = '