Skip to content

Commit 198e0b9

Browse files
author
Erin Altenhof-Long
committed
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 6ae6b47 commit 198e0b9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/ng/directive/selectSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,46 @@ describe('select', function() {
11151115
});
11161116
});
11171117

1118+
describe('disabled blank', function() {
1119+
it('should select disabled blank by default', function() {
1120+
var html = '<select ng-model="someModel" ng-options="c for c in choices">' +
1121+
'<option value="" disabled>Choose One</option>' +
1122+
'</select>';
1123+
scope.$apply(function() {
1124+
scope.choices = ['A', 'B', 'C'];
1125+
});
1126+
1127+
compile(html);
1128+
1129+
var options = element.find('option');
1130+
var optionToSelect = options.eq(0);
1131+
expect(optionToSelect.text()).toBe('Choose One');
1132+
expect(optionToSelect.prop('selected')).toBe(true);
1133+
expect(element.val()).toBe('');
1134+
1135+
dealoc(element);
1136+
});
1137+
1138+
1139+
it('should select disabled blank by default when select is required', function() {
1140+
var html = '<select ng-model="someModel" ng-options="c for c in choices" required>' +
1141+
'<option value="" disabled>Choose One</option>' +
1142+
'</select>';
1143+
scope.$apply(function() {
1144+
scope.choices = ['A', 'B', 'C'];
1145+
});
1146+
1147+
compile(html);
1148+
1149+
var options = element.find('option');
1150+
var optionToSelect = options.eq(0);
1151+
expect(optionToSelect.text()).toBe('Choose One');
1152+
expect(optionToSelect.prop('selected')).toBe(true);
1153+
expect(element.val()).toBe('');
1154+
1155+
dealoc(element);
1156+
});
1157+
});
11181158

11191159
describe('select-many', function() {
11201160

0 commit comments

Comments
 (0)