소스 검색

Add failing test for existing array selections

This adds a broken test that demonstrates the issue seen in
https://github.com/select2/select2/issues/3990 where existing selected
options are being reset once Select2 is initialized. This issue cannot
be reproduced on the options page [1] because the issue only appear to
happen if the selected option is not the first one in the list of
possible options.

[1]: https://select2.github.io/examples.html#data-array
Kevin Brown 9 년 전
부모
커밋
d1ed0a513a
1개의 변경된 파일28개의 추가작업 그리고 0개의 파일을 삭제
  1. 28 0
      tests/data/array-tests.js

+ 28 - 0
tests/data/array-tests.js

@@ -288,3 +288,31 @@ test('optgroup tags have the right properties', function (assert) {
     'The <optgroup> should have one child under it'
   );
 });
+
+test('existing selections are respected on initialization', function (assert) {
+   var $select = $(
+     '<select>' +
+        '<option>First</option>' +
+        '<option selected>Second</option>' +
+      '</select>'
+    );
+
+    var options = new Options({
+      data: [
+        {
+          id: 'Second',
+          text: 'Second'
+        },
+        {
+          id: 'Third',
+          text: 'Third'
+        }
+      ]
+    });
+
+    assert.equal($select.val(), 'Second');
+
+    var data = new ArrayData($select, options);
+
+    assert.equal($select.val(), 'Second');
+});