Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 29eaabc

Browse files
test(select): relax test for IE8 bug
There is a bug in IE8 (http://support.microsoft.com/kb/829907 and http://yuilibrary.com/forum-archive/forum/viewtopic.php@p=14826.html): when you clone an `<option>` element the selected attribute on the options can become invalid. This is not relevant to the proper behaviour of the `select` directive since it uses `prop` not `attr` to store the selected status of each option. This test is only interested in there being at least on option with the `selected` attribute, for conformance to accessibility guidelines. So we can safely relax the test to check this rather than concerning ourselves with which option actually has this attribute. Fixes 79538af Closes #8465
1 parent 2a60810 commit 29eaabc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/ng/directive/selectSpec.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,15 @@ describe('select', function() {
997997

998998

999999
it('should ensure that at least one option element has the "selected" attribute', function() {
1000+
function countSelected() {
1001+
var count = 0;
1002+
forEach(element.find('option'), function(option) {
1003+
count += option.getAttribute('selected') ? 1 : 0;
1004+
});
1005+
return count;
1006+
}
1007+
1008+
10001009
createSelect({
10011010
'ng-model': 'selected',
10021011
'ng-options': 'item.id as item.name for item in values'
@@ -1006,34 +1015,34 @@ describe('select', function() {
10061015
scope.values = [{id: 10, name: 'A'}, {id: 20, name: 'B'}];
10071016
});
10081017
expect(element.val()).toEqual('?');
1009-
expect(element.find('option').eq(0).attr('selected')).toEqual('selected');
1018+
expect(countSelected()).toEqual(1);
10101019

10111020
scope.$apply(function() {
10121021
scope.selected = 10;
10131022
});
10141023
// Here the ? option should disappear and the first real option should have selected attribute
10151024
expect(element.val()).toEqual('0');
1016-
expect(element.find('option').eq(0).attr('selected')).toEqual('selected');
1025+
expect(countSelected()).toEqual(1);
10171026

10181027
// Here the selected value is changed but we don't change the selected attribute
10191028
scope.$apply(function() {
10201029
scope.selected = 20;
10211030
});
10221031
expect(element.val()).toEqual('1');
1023-
expect(element.find('option').eq(0).attr('selected')).toEqual('selected');
1032+
expect(countSelected()).toEqual(1);
10241033

10251034
scope.$apply(function() {
10261035
scope.values.push({id: 30, name: 'C'});
10271036
});
10281037
expect(element.val()).toEqual('1');
1029-
expect(element.find('option').eq(0).attr('selected')).toEqual('selected');
1038+
expect(countSelected()).toEqual(1);
10301039

10311040
// Here the ? option should reappear and have selected attribute
10321041
scope.$apply(function() {
10331042
scope.selected = undefined;
10341043
});
10351044
expect(element.val()).toEqual('?');
1036-
expect(element.find('option').eq(0).attr('selected')).toEqual('selected');
1045+
expect(countSelected()).toEqual(1);
10371046
});
10381047
});
10391048

0 commit comments

Comments
 (0)