aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorChad Smith2013-03-19 10:22:06 +0000
committerPete Bacon Darwin2013-05-07 21:27:42 +0100
commit4622af3f075204e2d5ab33d5bd002074f2d940c9 (patch)
treef5426770279f781f1b6a43141f09c114e2e4cac0 /test
parentf046f6f73c910998a94f30a4cb4ed087b6325485 (diff)
downloadangular.js-4622af3f075204e2d5ab33d5bd002074f2d940c9.tar.bz2
fix(select): ensure empty option is not lost in IE9
Fix a check inside render for select elements with ngOptions, which compares the selected property of an element with it's desired state. Ensure the placeholder, if available, is explicitly selected if the model value can not be found in the option list. Without these fixes it's up to the browser implementation to decide which option to choose. In most browsers, this has the effect of displaying the first item in the list. In IE9 however, this causes the select to display nothing. Closes #2150, #1826
Diffstat (limited to 'test')
-rw-r--r--test/ng/directive/selectSpec.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js
index 2b56228d..91d09893 100644
--- a/test/ng/directive/selectSpec.js
+++ b/test/ng/directive/selectSpec.js
@@ -977,6 +977,19 @@ describe('select', function() {
expect(option.attr('id')).toBe('road-runner');
expect(option.attr('custom-attr')).toBe('custom-attr');
});
+
+ it('should be selected, if it is available and no other option is selected', function() {
+ // selectedIndex is used here because jqLite incorrectly reports element.val()
+ scope.$apply(function() {
+ scope.values = [{name: 'A'}];
+ });
+ createSingleSelect(true);
+ // ensure the first option (the blank option) is selected
+ expect(element[0].selectedIndex).toEqual(0);
+ scope.$digest();
+ // ensure the option has not changed following the digest
+ expect(element[0].selectedIndex).toEqual(0);
+ });
});
@@ -1099,6 +1112,21 @@ describe('select', function() {
browserTrigger(element, 'change');
expect(scope.selected).toEqual(['0']);
});
+
+ it('should deselect all options when model is emptied', function() {
+ createMultiSelect();
+ scope.$apply(function() {
+ scope.values = [{name: 'A'}, {name: 'B'}];
+ scope.selected = [scope.values[0]];
+ });
+ expect(element.find('option')[0].selected).toEqual(true);
+
+ scope.$apply(function() {
+ scope.selected.pop();
+ });
+
+ expect(element.find('option')[0].selected).toEqual(false);
+ })
});