Skip to content

Commit

Permalink
Migrate from expect to assert.expect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevin-brown committed May 24, 2016
1 parent 2805fa7 commit a74547a
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 26 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"console": false,
"define": false,
"document": false,
"expect": false,
"MockContainer": false,
"module": false,
"QUnit": false,
Expand Down
4 changes: 2 additions & 2 deletions tests/data/inputData-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions tests/data/tokenizer-tests.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/dropdown/positioning-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module('Dropdown - attachBody - positioning');

test('appends to the dropdown parent', function (assert) {
expect(4);
assert.expect(4);

var $ = require('jquery');

Expand Down
8 changes: 4 additions & 4 deletions tests/dropdown/selectOnClose-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($element));
Expand All @@ -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 = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($element));
Expand Down Expand Up @@ -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 = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($element));
Expand Down Expand Up @@ -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 = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($element));
Expand Down
2 changes: 1 addition & 1 deletion tests/dropdown/stopPropagation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tests/options/deprecated-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<select></select>');
var called = false;
Expand Down Expand Up @@ -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 = $('<select></select>');
var called = false;
Expand Down Expand Up @@ -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 = $('<select><option value="3" selected>4</option></select>');
var called = 0;
Expand Down Expand Up @@ -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 = $('<select></select>');
var called = false;
Expand Down
6 changes: 3 additions & 3 deletions tests/results/focusing-tests.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion tests/selection/allowClear-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
8 changes: 4 additions & 4 deletions tests/selection/search-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/selection/stopPropagation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a74547a

Please sign in to comment.