From 4febcb4b492c322c71bdef579cc4ad99ea86e150 Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Sun, 1 Mar 2015 09:33:48 -0500 Subject: [Fixes #15953] Implement assert.expect in each unit test [Fixes #15953] Implement `assert.expect` in each unit test --- js/tests/unit/affix.js | 6 +++++ js/tests/unit/alert.js | 6 +++++ js/tests/unit/button.js | 12 ++++++++++ js/tests/unit/carousel.js | 21 ++++++++++++++++++ js/tests/unit/collapse.js | 27 +++++++++++++++++++---- js/tests/unit/dropdown.js | 15 +++++++++++++ js/tests/unit/modal.js | 24 ++++++++++++++++++++ js/tests/unit/popover.js | 15 +++++++++++++ js/tests/unit/scrollspy.js | 8 +++++++ js/tests/unit/tab.js | 11 ++++++++++ js/tests/unit/tooltip.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 196 insertions(+), 4 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index d2c74f464..3a6918f86 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -4,6 +4,7 @@ $(function () { QUnit.module('affix plugin') QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) assert.ok($(document.body).affix, 'affix method is defined') }) @@ -19,10 +20,12 @@ $(function () { }) QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) assert.strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)') }) QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) var $el = $('
') var $affix = $el.bootstrapAffix() assert.ok($affix instanceof $, 'returns jquery collection') @@ -30,12 +33,14 @@ $(function () { }) QUnit.test('should exit early if element is not visible', function (assert) { + assert.expect(1) var $affix = $('
').bootstrapAffix() $affix.data('bs.affix').checkPosition() assert.ok(!$affix.hasClass('affix'), 'affix class was not added') }) QUnit.test('should trigger affixed event after affix', function (assert) { + assert.expect(2) var done = assert.async() var templateHTML = '
' @@ -70,6 +75,7 @@ $(function () { }) QUnit.test('should affix-top when scrolling up to offset when parent has padding', function (assert) { + assert.expect(1) var done = assert.async() var templateHTML = '
' diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index 75ae2d2ef..0768a1e11 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -4,6 +4,7 @@ $(function () { QUnit.module('alert plugin') QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) assert.ok($(document.body).alert, 'alert method is defined') }) @@ -19,10 +20,12 @@ $(function () { }) QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) assert.strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)') }) QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) var $el = $('
') var $alert = $el.bootstrapAlert() assert.ok($alert instanceof $, 'returns jquery collection') @@ -30,6 +33,7 @@ $(function () { }) QUnit.test('should fade element out on clicking .close', function (assert) { + assert.expect(1) var alertHTML = '
' + '×' + '

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

' @@ -42,6 +46,7 @@ $(function () { }) QUnit.test('should remove element when clicking .close', function (assert) { + assert.expect(2) var alertHTML = '
' + '×' + '

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

' @@ -56,6 +61,7 @@ $(function () { }) QUnit.test('should not fire closed when close is prevented', function (assert) { + assert.expect(1) var done = assert.async() $('
') .on('close.bs.alert', function (e) { diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 5a547a370..7788addd1 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -4,6 +4,7 @@ $(function () { QUnit.module('button plugin') QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) assert.ok($(document.body).button, 'button method is defined') }) @@ -19,10 +20,12 @@ $(function () { }) QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) assert.strictEqual($.fn.button, undefined, 'button was set back to undefined (org value)') }) QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) var $el = $('
') var $button = $el.bootstrapButton() assert.ok($button instanceof $, 'returns jquery collection') @@ -30,6 +33,7 @@ $(function () { }) QUnit.test('should return set state to loading', function (assert) { + assert.expect(4) var $btn = $('') assert.strictEqual($btn.html(), 'mdo', 'btn text equals mdo') $btn.bootstrapButton('loading') @@ -43,6 +47,7 @@ $(function () { }) QUnit.test('should return reset state', function (assert) { + assert.expect(7) var $btn = $('') assert.strictEqual($btn.html(), 'mdo', 'btn text equals mdo') $btn.bootstrapButton('loading') @@ -64,6 +69,7 @@ $(function () { }) QUnit.test('should work with an empty string as reset state', function (assert) { + assert.expect(7) var $btn = $('') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') $btn.bootstrapButton('toggle') @@ -92,6 +99,7 @@ $(function () { }) QUnit.test('should toggle active when btn children are clicked', function (assert) { + assert.expect(2) var $btn = $('') var $inner = $('') $btn @@ -103,6 +111,7 @@ $(function () { }) QUnit.test('should toggle aria-pressed', function (assert) { + assert.expect(2) var $btn = $('') assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') $btn.bootstrapButton('toggle') @@ -110,6 +119,7 @@ $(function () { }) QUnit.test('should toggle aria-pressed when btn children are clicked', function (assert) { + assert.expect(2) var $btn = $('') var $inner = $('') $btn @@ -121,6 +131,7 @@ $(function () { }) QUnit.test('should toggle active when btn children are clicked within btn-group', function (assert) { + assert.expect(2) var $btngroup = $('
') var $btn = $('') var $inner = $('') @@ -133,6 +144,7 @@ $(function () { }) QUnit.test('should check for closest matching toggle', function (assert) { + assert.expect(12) var groupHTML = '
' + '