Skip to content

Commit

Permalink
Add failing test for existing array selections
Browse files Browse the repository at this point in the history
This adds a broken test that demonstrates the issue seen in
select2#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
  • Loading branch information
kevin-brown authored and tzellman committed Feb 2, 2016
1 parent c14e244 commit bf07885
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/data/array-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit bf07885

Please sign in to comment.