From d1ed0a513ab60b41e7a748cec8ffa345544cba27 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 3 Jan 2016 18:21:09 -0500 Subject: [PATCH] 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 --- tests/data/array-tests.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/data/array-tests.js b/tests/data/array-tests.js index 6096ecfa..65a6e32c 100644 --- a/tests/data/array-tests.js +++ b/tests/data/array-tests.js @@ -288,3 +288,31 @@ test('optgroup tags have the right properties', function (assert) { 'The should have one child under it' ); }); + +test('existing selections are respected on initialization', function (assert) { + var $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'); +}); \ No newline at end of file