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:
Paul O'Shannessy
2013-10-15 10:39:51 -07:00
committed by Paul O’Shannessy
parent 287f5b578c
commit b0455f4670
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -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,