Fixed consistency of behavior boolean properties

This commit is contained in:
Toru Kobayashi
2015-08-05 18:57:10 +09:00
parent c97ed7b804
commit eb4e44a3c9
2 changed files with 12 additions and 0 deletions
@@ -173,6 +173,9 @@ var DOMPropertyOperations = {
// ('' + value) makes it output the correct toString()-value.
if (namespace) {
node.setAttributeNS(namespace, attributeName, '' + value);
} else if (propertyInfo.hasBooleanValue ||
(propertyInfo.hasOverloadedBooleanValue && value === true)) {
node.setAttribute(attributeName, '');
} else {
node.setAttribute(attributeName, '' + value);
}
@@ -224,6 +224,15 @@ describe('DOMPropertyOperations', function() {
.toEqual(['http://www.w3.org/1999/xlink', 'xlink:href', 'about:blank']);
});
it('should set values as boolean properties', function() {
DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', 'disabled');
expect(stubNode.getAttribute('disabled')).toBe('');
DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', true);
expect(stubNode.getAttribute('disabled')).toBe('');
DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', false);
expect(stubNode.getAttribute('disabled')).toBe(null);
});
it('should convert attribute values to string first', function() {
// Browsers default to this behavior, but some test environments do not.
// This ensures that we have consistent behavior.