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.
Paul O'Shannessy committed
Oct 15, 2013 at 10:37 UTC
b0455f46709fca94da0b6126b719d6dd07605e65
2 files changed
+10
-2
src/dom/DOMPropertyOperations.js
+2
-2
@@ -109,7 +109,7 @@ var DOMPropertyOperations = {
109
if (DOMProperty.hasBooleanValue[name] && !value) {
110
node.removeAttribute(DOMProperty.getAttributeName[name]);
111
} else {
112
- node.setAttribute(DOMProperty.getAttributeName[name], value);
112
+ node.setAttribute(DOMProperty.getAttributeName[name], '' + value);
113
}
114
} else {
115
var propName = DOMProperty.getPropertyName[name];
@@ -118,7 +118,7 @@ var DOMPropertyOperations = {
118
}
119
}
120
} else if (DOMProperty.isCustomAttribute(name)) {
121
- node.setAttribute(name, value);
121
+ node.setAttribute(name, '' + value);
122
} else if (__DEV__) {
123
warnUnknownProperty(name);
124
}
src/dom/__tests__/DOMPropertyOperations-test.js
+8
@@ -132,6 +132,14 @@ describe('DOMPropertyOperations', function() {
132
expect(stubNode.role).toBeUndefined();
133
});
134
135
+ it('should convert attribute values to string first', function() {
136
+ // Browsers default to this behavior, but some test environments do not.
137
+ // This ensures that we have consistent behavior.
138
+ var obj = {toString: function() { return '<html>'; }};
139
+ DOMPropertyOperations.setValueForProperty(stubNode, 'role', obj);
140
+ expect(stubNode.getAttribute('role')).toBe('<html>');
141
+ });
142
+
143
it('should remove for falsey boolean properties', function() {
144
DOMPropertyOperations.setValueForProperty(
145
stubNode,