mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Ensure attribute values are strings
`jsdom` behavers differently than browsers here and we should ensure that we are consistent. Browsers should be (and are) converting to a string first, while `jsdom` doesn't.
This commit is contained in:
committed by
Paul O’Shannessy
parent
287f5b578c
commit
b0455f4670
@@ -109,7 +109,7 @@ var DOMPropertyOperations = {
|
||||
if (DOMProperty.hasBooleanValue[name] && !value) {
|
||||
node.removeAttribute(DOMProperty.getAttributeName[name]);
|
||||
} else {
|
||||
node.setAttribute(DOMProperty.getAttributeName[name], value);
|
||||
node.setAttribute(DOMProperty.getAttributeName[name], '' + value);
|
||||
}
|
||||
} else {
|
||||
var propName = DOMProperty.getPropertyName[name];
|
||||
@@ -118,7 +118,7 @@ var DOMPropertyOperations = {
|
||||
}
|
||||
}
|
||||
} else if (DOMProperty.isCustomAttribute(name)) {
|
||||
node.setAttribute(name, value);
|
||||
node.setAttribute(name, '' + value);
|
||||
} else if (__DEV__) {
|
||||
warnUnknownProperty(name);
|
||||
}
|
||||
|
||||
@@ -132,6 +132,14 @@ describe('DOMPropertyOperations', function() {
|
||||
expect(stubNode.role).toBeUndefined();
|
||||
});
|
||||
|
||||
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.
|
||||
var obj = {toString: function() { return '<html>'; }};
|
||||
DOMPropertyOperations.setValueForProperty(stubNode, 'role', obj);
|
||||
expect(stubNode.getAttribute('role')).toBe('<html>');
|
||||
});
|
||||
|
||||
it('should remove for falsey boolean properties', function() {
|
||||
DOMPropertyOperations.setValueForProperty(
|
||||
stubNode,
|
||||
|
||||
Reference in New Issue
Block a user