From 4a2b183e48a834bf345a80d27ca37327b25e9018 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Wed, 14 Jun 2017 10:48:58 +0200 Subject: [PATCH] Fix unit tests with no assertion --- js/tests/unit/dropdown.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 1dd675b0b6..7e96745ab6 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -45,7 +45,8 @@ $(function () { }) QUnit.test('should not open dropdown if target is disabled via attribute', function (assert) { - assert.expect(0) + assert.expect(1) + var done = assert.async() var dropdownHTML = '
' + '' + '
' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() - setTimeout(function () { - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') - }, 300) + $(dropdownHTML).appendTo('#qunit-fixture') + var $dropdown = $('#qunit-fixture').find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown.on('click', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show')) + done() + }) + $dropdown.trigger($.Event('click')) }) QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) { @@ -77,7 +81,10 @@ $(function () { + '' + '' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() $dropdown .parent('.dropdown') .on('shown.bs.dropdown', function () { @@ -118,7 +125,8 @@ $(function () { }) QUnit.test('should not open dropdown if target is disabled via class', function (assert) { - assert.expect(0) + assert.expect(1) + var done = assert.async() var dropdownHTML = '
' + '' + '
' + '' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') - setTimeout(function () { - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') - }, 300) + + $(dropdownHTML).appendTo('#qunit-fixture') + var $dropdown = $('#qunit-fixture').find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown.on('click', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show')) + done() + }) + $dropdown.trigger($.Event('click')) }) QUnit.test('should add class show to menu if clicked', function (assert) { -- 2.47.2