From a74547aaa76d406dd0b8a441d0a84dc9694a2829 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Mon, 23 May 2016 23:38:45 -0400 Subject: [PATCH] Migrate from expect to assert.expect After we upgraded to QUnit 1.23.1, we gained support for assert.expect(). This allows us to guard against any race conditions within tests, because now expect() will be linked to the specific test instead of the current running test. --- .jshintrc | 1 - tests/data/inputData-tests.js | 4 ++-- tests/data/tokenizer-tests.js | 8 ++++---- tests/dropdown/positioning-tests.js | 2 +- tests/dropdown/selectOnClose-tests.js | 8 ++++---- tests/dropdown/stopPropagation-tests.js | 2 +- tests/options/deprecated-tests.js | 8 ++++---- tests/results/focusing-tests.js | 6 +++--- tests/selection/allowClear-tests.js | 2 +- tests/selection/search-tests.js | 8 ++++---- tests/selection/stopPropagation-tests.js | 2 +- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.jshintrc b/.jshintrc index aee0cce6..94299268 100644 --- a/.jshintrc +++ b/.jshintrc @@ -9,7 +9,6 @@ "console": false, "define": false, "document": false, - "expect": false, "MockContainer": false, "module": false, "QUnit": false, diff --git a/tests/data/inputData-tests.js b/tests/data/inputData-tests.js index 90b6fef2..f2124efb 100644 --- a/tests/data/inputData-tests.js +++ b/tests/data/inputData-tests.js @@ -93,7 +93,7 @@ test('options can be unselected individually', function (assert) { }); test('default values can be set', function (assert) { - expect(4); + assert.expect(4); var options = new Options({ data: [ @@ -128,7 +128,7 @@ test('default values can be set', function (assert) { }); test('no default value', function (assert) { - expect(2); + assert.expect(2); var options = new Options({ data: [ diff --git a/tests/data/tokenizer-tests.js b/tests/data/tokenizer-tests.js index 011dca4c..2fa01211 100644 --- a/tests/data/tokenizer-tests.js +++ b/tests/data/tokenizer-tests.js @@ -1,7 +1,7 @@ module('Data adaptor - Tokenizer'); test('triggers the select event', function (assert) { - expect(2); + assert.expect(2); var SelectData = require('select2/data/select'); var Tokenizer = require('select2/data/tokenizer'); @@ -43,7 +43,7 @@ test('triggers the select event', function (assert) { }); test('createTag can return null', function (assert) { - expect(3); + assert.expect(3); var SelectData = require('select2/data/select'); var Tokenizer = require('select2/data/tokenizer'); @@ -92,7 +92,7 @@ test('createTag can return null', function (assert) { }); test('createTag returning null does not cut the term', function (assert) { - expect(4); + assert.expect(4); var SelectData = require('select2/data/select'); var Tokenizer = require('select2/data/tokenizer'); @@ -171,7 +171,7 @@ test('createTag returning null does not cut the term', function (assert) { }); test('works with multiple tokens given', function (assert) { - expect(4); + assert.expect(4); var SelectData = require('select2/data/select'); var Tokenizer = require('select2/data/tokenizer'); diff --git a/tests/dropdown/positioning-tests.js b/tests/dropdown/positioning-tests.js index 8ff3bac3..37c2b064 100644 --- a/tests/dropdown/positioning-tests.js +++ b/tests/dropdown/positioning-tests.js @@ -1,7 +1,7 @@ module('Dropdown - attachBody - positioning'); test('appends to the dropdown parent', function (assert) { - expect(4); + assert.expect(4); var $ = require('jquery'); diff --git a/tests/dropdown/selectOnClose-tests.js b/tests/dropdown/selectOnClose-tests.js index 96b88caf..3f1d1d41 100644 --- a/tests/dropdown/selectOnClose-tests.js +++ b/tests/dropdown/selectOnClose-tests.js @@ -17,7 +17,7 @@ var options = new Options({ }); test('will not trigger if no results were given', function (assert) { - expect(0); + assert.expect(0); var $element = $(''); var select = new ModifiedResults($element, options, new SelectData($element)); @@ -35,7 +35,7 @@ test('will not trigger if no results were given', function (assert) { }); test('will not trigger if the results list is empty', function (assert) { - expect(1); + assert.expect(1); var $element = $(''); var select = new ModifiedResults($element, options, new SelectData($element)); @@ -63,7 +63,7 @@ test('will not trigger if the results list is empty', function (assert) { }); test('will not trigger if no results here highlighted', function (assert) { - expect(2); + assert.expect(2); var $element = $(''); var select = new ModifiedResults($element, options, new SelectData($element)); @@ -102,7 +102,7 @@ test('will not trigger if no results here highlighted', function (assert) { }); test('will trigger if there is a highlighted result', function (assert) { - expect(2); + assert.expect(2); var $element = $(''); var select = new ModifiedResults($element, options, new SelectData($element)); diff --git a/tests/dropdown/stopPropagation-tests.js b/tests/dropdown/stopPropagation-tests.js index 921787f9..240a3e66 100644 --- a/tests/dropdown/stopPropagation-tests.js +++ b/tests/dropdown/stopPropagation-tests.js @@ -12,7 +12,7 @@ var CustomDropdown = Utils.Decorate(Dropdown, StopPropagation); var options = new Options(); test('click event does not propagate', function (assert) { - expect(1); + assert.expect(1); var $container = $('#qunit-fixture .event-container'); var container = new MockContainer(); diff --git a/tests/options/deprecated-tests.js b/tests/options/deprecated-tests.js index cdd732df..a51bba31 100644 --- a/tests/options/deprecated-tests.js +++ b/tests/options/deprecated-tests.js @@ -4,7 +4,7 @@ var $ = require('jquery'); var Options = require('select2/options'); test('converted into dataAdapter.current', function (assert) { - expect(5); + assert.expect(5); var $test = $(''); var called = false; @@ -51,7 +51,7 @@ test('converted into dataAdapter.current', function (assert) { }); test('single option converted to array automatically', function (assert) { - expect(2); + assert.expect(2); var $test = $(''); var called = false; @@ -81,7 +81,7 @@ test('single option converted to array automatically', function (assert) { }); test('only called once', function (assert) { - expect(8); + assert.expect(8); var $test = $(''); var called = 0; @@ -160,7 +160,7 @@ test('only called once', function (assert) { module('Options - Deprecated - query'); test('converted into dataAdapter.query automatically', function (assert) { - expect(6); + assert.expect(6); var $test = $(''); var called = false; diff --git a/tests/results/focusing-tests.js b/tests/results/focusing-tests.js index e75068a7..135d0016 100644 --- a/tests/results/focusing-tests.js +++ b/tests/results/focusing-tests.js @@ -1,7 +1,7 @@ module('Results - highlighting results'); test('results:all with no data skips results:focus', function (assert) { - expect(0); + assert.expect(0); var $ = require('jquery'); @@ -43,7 +43,7 @@ test('results:all with no data skips results:focus', function (assert) { }); test('results:all triggers results:focus on the first item', function (assert) { - expect(2); + assert.expect(2); var $ = require('jquery'); @@ -91,7 +91,7 @@ test('results:all triggers results:focus on the first item', function (assert) { }); test('results:append does not trigger results:focus', function (assert) { - expect(0); + assert.expect(0); var $ = require('jquery'); diff --git a/tests/selection/allowClear-tests.js b/tests/selection/allowClear-tests.js index e7f4fd86..efa132aa 100644 --- a/tests/selection/allowClear-tests.js +++ b/tests/selection/allowClear-tests.js @@ -109,7 +109,7 @@ test('clicking clear will set the placeholder value', function (assert) { }); test('clicking clear will trigger the unselect event', function (assert) { - expect(3); + assert.expect(3); var $element = $('#qunit-fixture .single-with-placeholder'); diff --git a/tests/selection/search-tests.js b/tests/selection/search-tests.js index 1c1b813b..43345d72 100644 --- a/tests/selection/search-tests.js +++ b/tests/selection/search-tests.js @@ -10,7 +10,7 @@ var Utils = require('select2/utils'); var options = new Options({}); test('backspace will remove a choice', function (assert) { - expect(3); + assert.expect(3); var KEYS = require('select2/keys'); @@ -52,7 +52,7 @@ test('backspace will remove a choice', function (assert) { }); test('backspace will set the search text', function (assert) { - expect(3); + assert.expect(3); var KEYS = require('select2/keys'); @@ -94,7 +94,7 @@ test('updating selection does not shift the focus', function (assert) { // Check for IE 8, which triggers a false negative during testing if (window.attachEvent && !window.addEventListener) { // We must expect 0 assertions or the test will fail - expect(0); + assert.expect(0); return; } @@ -142,7 +142,7 @@ test('the focus event shifts the focus', function (assert) { // Check for IE 8, which triggers a false negative during testing if (window.attachEvent && !window.addEventListener) { // We must expect 0 assertions or the test will fail - expect(0); + assert.expect(0); return; } diff --git a/tests/selection/stopPropagation-tests.js b/tests/selection/stopPropagation-tests.js index e1bda241..d8d8897b 100644 --- a/tests/selection/stopPropagation-tests.js +++ b/tests/selection/stopPropagation-tests.js @@ -12,7 +12,7 @@ var CutomSelection = Utils.Decorate(SingleSelection, StopPropagation); var options = new Options(); test('click event does not propagate', function (assert) { - expect(1); + assert.expect(1); var $container = $('#qunit-fixture .event-container'); var container = new MockContainer();