Skip to content

Commit b770c35

Browse files
Erin Altenhof-Longpetebacondarwin
authored andcommitted
test(select): add test cases for selects with blank disabled options
An earlier commit dc149de caused an error where the first option of a select would be skipped over if it had a blank disabled value. These tests demonstrate that with that commit in place, blank disabled options are skipped in a select. When the commit is reverted, the correct behavior is seen that the blank disabled option is still selected in both selects marked with required and those that have optional choices. Relates to angular#7715
1 parent 812277c commit b770c35

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

test/ng/directive/selectSpec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,46 @@ describe('select', function() {
11361136
});
11371137
});
11381138

1139+
describe('disabled blank', function() {
1140+
it('should select disabled blank by default', function() {
1141+
var html = '<select ng-model="someModel" ng-options="c for c in choices">' +
1142+
'<option value="" disabled>Choose One</option>' +
1143+
'</select>';
1144+
scope.$apply(function() {
1145+
scope.choices = ['A', 'B', 'C'];
1146+
});
1147+
1148+
compile(html);
1149+
1150+
var options = element.find('option');
1151+
var optionToSelect = options.eq(0);
1152+
expect(optionToSelect.text()).toBe('Choose One');
1153+
expect(optionToSelect.prop('selected')).toBe(true);
1154+
expect(element[0].value).toBe('');
1155+
1156+
dealoc(element);
1157+
});
1158+
1159+
1160+
it('should select disabled blank by default when select is required', function() {
1161+
var html = '<select ng-model="someModel" ng-options="c for c in choices" required>' +
1162+
'<option value="" disabled>Choose One</option>' +
1163+
'</select>';
1164+
scope.$apply(function() {
1165+
scope.choices = ['A', 'B', 'C'];
1166+
});
1167+
1168+
compile(html);
1169+
1170+
var options = element.find('option');
1171+
var optionToSelect = options.eq(0);
1172+
expect(optionToSelect.text()).toBe('Choose One');
1173+
expect(optionToSelect.prop('selected')).toBe(true);
1174+
expect(element[0].value).toBe('');
1175+
1176+
dealoc(element);
1177+
});
1178+
});
11391179

11401180
describe('select-many', function() {
11411181

0 commit comments

Comments
 (0)