1
0
mirror of synced 2024-11-24 22:06:07 +03:00

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.
This commit is contained in:
Kevin Brown 2016-05-23 23:38:45 -04:00
parent 2805fa7aa4
commit a74547aaa7
11 changed files with 25 additions and 26 deletions

View File

@ -9,7 +9,6 @@
"console": false, "console": false,
"define": false, "define": false,
"document": false, "document": false,
"expect": false,
"MockContainer": false, "MockContainer": false,
"module": false, "module": false,
"QUnit": false, "QUnit": false,

View File

@ -93,7 +93,7 @@ test('options can be unselected individually', function (assert) {
}); });
test('default values can be set', function (assert) { test('default values can be set', function (assert) {
expect(4); assert.expect(4);
var options = new Options({ var options = new Options({
data: [ data: [
@ -128,7 +128,7 @@ test('default values can be set', function (assert) {
}); });
test('no default value', function (assert) { test('no default value', function (assert) {
expect(2); assert.expect(2);
var options = new Options({ var options = new Options({
data: [ data: [

View File

@ -1,7 +1,7 @@
module('Data adaptor - Tokenizer'); module('Data adaptor - Tokenizer');
test('triggers the select event', function (assert) { test('triggers the select event', function (assert) {
expect(2); assert.expect(2);
var SelectData = require('select2/data/select'); var SelectData = require('select2/data/select');
var Tokenizer = require('select2/data/tokenizer'); var Tokenizer = require('select2/data/tokenizer');
@ -43,7 +43,7 @@ test('triggers the select event', function (assert) {
}); });
test('createTag can return null', function (assert) { test('createTag can return null', function (assert) {
expect(3); assert.expect(3);
var SelectData = require('select2/data/select'); var SelectData = require('select2/data/select');
var Tokenizer = require('select2/data/tokenizer'); 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) { test('createTag returning null does not cut the term', function (assert) {
expect(4); assert.expect(4);
var SelectData = require('select2/data/select'); var SelectData = require('select2/data/select');
var Tokenizer = require('select2/data/tokenizer'); 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) { test('works with multiple tokens given', function (assert) {
expect(4); assert.expect(4);
var SelectData = require('select2/data/select'); var SelectData = require('select2/data/select');
var Tokenizer = require('select2/data/tokenizer'); var Tokenizer = require('select2/data/tokenizer');

View File

@ -1,7 +1,7 @@
module('Dropdown - attachBody - positioning'); module('Dropdown - attachBody - positioning');
test('appends to the dropdown parent', function (assert) { test('appends to the dropdown parent', function (assert) {
expect(4); assert.expect(4);
var $ = require('jquery'); var $ = require('jquery');

View File

@ -17,7 +17,7 @@ var options = new Options({
}); });
test('will not trigger if no results were given', function (assert) { test('will not trigger if no results were given', function (assert) {
expect(0); assert.expect(0);
var $element = $('<select></select>'); var $element = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($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) { test('will not trigger if the results list is empty', function (assert) {
expect(1); assert.expect(1);
var $element = $('<select></select>'); var $element = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($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) { test('will not trigger if no results here highlighted', function (assert) {
expect(2); assert.expect(2);
var $element = $('<select></select>'); var $element = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($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) { test('will trigger if there is a highlighted result', function (assert) {
expect(2); assert.expect(2);
var $element = $('<select></select>'); var $element = $('<select></select>');
var select = new ModifiedResults($element, options, new SelectData($element)); var select = new ModifiedResults($element, options, new SelectData($element));

View File

@ -12,7 +12,7 @@ var CustomDropdown = Utils.Decorate(Dropdown, StopPropagation);
var options = new Options(); var options = new Options();
test('click event does not propagate', function (assert) { test('click event does not propagate', function (assert) {
expect(1); assert.expect(1);
var $container = $('#qunit-fixture .event-container'); var $container = $('#qunit-fixture .event-container');
var container = new MockContainer(); var container = new MockContainer();

View File

@ -4,7 +4,7 @@ var $ = require('jquery');
var Options = require('select2/options'); var Options = require('select2/options');
test('converted into dataAdapter.current', function (assert) { test('converted into dataAdapter.current', function (assert) {
expect(5); assert.expect(5);
var $test = $('<select></select>'); var $test = $('<select></select>');
var called = false; var called = false;
@ -51,7 +51,7 @@ test('converted into dataAdapter.current', function (assert) {
}); });
test('single option converted to array automatically', function (assert) { test('single option converted to array automatically', function (assert) {
expect(2); assert.expect(2);
var $test = $('<select></select>'); var $test = $('<select></select>');
var called = false; var called = false;
@ -81,7 +81,7 @@ test('single option converted to array automatically', function (assert) {
}); });
test('only called once', function (assert) { test('only called once', function (assert) {
expect(8); assert.expect(8);
var $test = $('<select><option value="3" selected>4</option></select>'); var $test = $('<select><option value="3" selected>4</option></select>');
var called = 0; var called = 0;
@ -160,7 +160,7 @@ test('only called once', function (assert) {
module('Options - Deprecated - query'); module('Options - Deprecated - query');
test('converted into dataAdapter.query automatically', function (assert) { test('converted into dataAdapter.query automatically', function (assert) {
expect(6); assert.expect(6);
var $test = $('<select></select>'); var $test = $('<select></select>');
var called = false; var called = false;

View File

@ -1,7 +1,7 @@
module('Results - highlighting results'); module('Results - highlighting results');
test('results:all with no data skips results:focus', function (assert) { test('results:all with no data skips results:focus', function (assert) {
expect(0); assert.expect(0);
var $ = require('jquery'); 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) { test('results:all triggers results:focus on the first item', function (assert) {
expect(2); assert.expect(2);
var $ = require('jquery'); 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) { test('results:append does not trigger results:focus', function (assert) {
expect(0); assert.expect(0);
var $ = require('jquery'); var $ = require('jquery');

View File

@ -109,7 +109,7 @@ test('clicking clear will set the placeholder value', function (assert) {
}); });
test('clicking clear will trigger the unselect event', function (assert) { test('clicking clear will trigger the unselect event', function (assert) {
expect(3); assert.expect(3);
var $element = $('#qunit-fixture .single-with-placeholder'); var $element = $('#qunit-fixture .single-with-placeholder');

View File

@ -10,7 +10,7 @@ var Utils = require('select2/utils');
var options = new Options({}); var options = new Options({});
test('backspace will remove a choice', function (assert) { test('backspace will remove a choice', function (assert) {
expect(3); assert.expect(3);
var KEYS = require('select2/keys'); 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) { test('backspace will set the search text', function (assert) {
expect(3); assert.expect(3);
var KEYS = require('select2/keys'); 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 // Check for IE 8, which triggers a false negative during testing
if (window.attachEvent && !window.addEventListener) { if (window.attachEvent && !window.addEventListener) {
// We must expect 0 assertions or the test will fail // We must expect 0 assertions or the test will fail
expect(0); assert.expect(0);
return; 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 // Check for IE 8, which triggers a false negative during testing
if (window.attachEvent && !window.addEventListener) { if (window.attachEvent && !window.addEventListener) {
// We must expect 0 assertions or the test will fail // We must expect 0 assertions or the test will fail
expect(0); assert.expect(0);
return; return;
} }

View File

@ -12,7 +12,7 @@ var CutomSelection = Utils.Decorate(SingleSelection, StopPropagation);
var options = new Options(); var options = new Options();
test('click event does not propagate', function (assert) { test('click event does not propagate', function (assert) {
expect(1); assert.expect(1);
var $container = $('#qunit-fixture .event-container'); var $container = $('#qunit-fixture .event-container');
var container = new MockContainer(); var container = new MockContainer();