Browse Source

Changed tests to not use deepEqual

We should only be checking the option values that matter, such as
`id` and `text`, instead of checking all of the option values. This
will prevent unexpected breaking when new properties are added to
the options.

Existing properties should be covered by tests to avoid regressions.
Kevin Brown 10 years ago
parent
commit
e018a6f69e
4 changed files with 81 additions and 41 deletions
  1. 0 0
      dist/js/select2.full.min.js
  2. 0 0
      dist/js/select2.min.js
  3. 24 14
      tests/data/array-tests.js
  4. 57 27
      tests/data/select-tests.js

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 24 - 14
tests/data/array-tests.js

@@ -27,9 +27,9 @@ test('current gets default for single', function (assert) {
   var data = new ArrayData($select, options);
   var data = new ArrayData($select, options);
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [],
+    assert.equal(
+      val.length,
+      0,
       'There should be no default selection.'
       'There should be no default selection.'
     );
     );
   });
   });
@@ -41,9 +41,9 @@ test('current gets default for multiple', function (assert) {
   var data = new ArrayData($select, options);
   var data = new ArrayData($select, options);
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [],
+    assert.equal(
+      val.length,
+      0,
       'There should be no default selection.'
       'There should be no default selection.'
     );
     );
   });
   });
@@ -57,14 +57,24 @@ test('current works with existing selections', function (assert) {
   $select.val(['3']);
   $select.val(['3']);
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [{
-        id: '3',
-        text: 'Three',
-        disabled: false
-      }],
-      'The text and id should match the value and text for the option tag.'
+    assert.equal(
+      val.length,
+      1,
+      'There should only be one existing selection'
+    );
+
+    var option = val[0];
+
+    assert.equal(
+      option.id,
+      '3',
+      'The id should be equal to the value of the option tag'
+    );
+
+    assert.equal(
+      option.text,
+      'Three',
+      'The text should be equal to the text of the option tag'
     );
     );
   });
   });
 });
 });

+ 57 - 27
tests/data/select-tests.js

@@ -12,14 +12,24 @@ test('current gets default for single', function (assert) {
   var data = new SelectData($select, options);
   var data = new SelectData($select, options);
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [{
-        id: 'default',
-        text: 'Default',
-        disabled: false
-      }],
-      'The first option should be selected by default (by the browser).'
+    assert.equal(
+      val.length,
+      1,
+      'There should only be one selected option'
+    );
+
+    var option = val[0];
+
+    assert.equal(
+      option.id,
+      'default',
+      'The value of the option tag should be the id'
+    );
+
+    assert.equal(
+      option.text,
+      'Default',
+      'The text within the option tag should be the text'
     );
     );
   });
   });
 });
 });
@@ -30,9 +40,9 @@ test('current gets default for multiple', function (assert) {
   var data = new SelectData($select, options);
   var data = new SelectData($select, options);
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [],
+    assert.equal(
+      val.length,
+      0,
       'Multiple selects have no default selection.'
       'Multiple selects have no default selection.'
     );
     );
   });
   });
@@ -46,14 +56,24 @@ test('current gets options with explicit value', function (assert) {
   $select.val('1');
   $select.val('1');
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [{
-        id: '1',
-        text: 'One',
-        disabled: false
-      }],
-      'The text and id should match the value and text for the option tag.'
+    assert.equal(
+      val.length,
+      1,
+      'There should be one selected option'
+    );
+
+    var option = val[0];
+
+    assert.equal(
+      option.id,
+      '1',
+      'The option value should be the selected id'
+    );
+
+    assert.equal(
+      option.text,
+      'One',
+      'The text should match the text for the option tag'
     );
     );
   });
   });
 });
 });
@@ -66,14 +86,24 @@ test('current gets options with implicit value', function (assert) {
   $select.val('2');
   $select.val('2');
 
 
   data.current(function (val) {
   data.current(function (val) {
-    assert.deepEqual(
-      val,
-      [{
-        id: '2',
-        text: '2',
-        disabled: false
-      }],
-      'The text and id should match the text within the option tag.'
+    assert.equal(
+      val.length,
+      1,
+      'There should only be one selected value'
+    );
+
+    var option = val[0];
+
+    assert.equal(
+      option.id,
+      '2',
+      'The id should be the same as the option text'
+    );
+
+    assert.equal(
+      option.text,
+      '2',
+      'The text should be the same as the option text'
     );
     );
   });
   });
 });
 });

Some files were not shown because too many files changed in this diff