Skip to content

Commit

Permalink
Ensure attribute values are strings
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
zpao committed Oct 15, 2013
1 parent 287f5b5 commit b0455f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dom/DOMPropertyOperations.js
Expand Up @@ -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];
Expand All @@ -118,7 +118,7 @@ var DOMPropertyOperations = {
}
}
} else if (DOMProperty.isCustomAttribute(name)) {
node.setAttribute(name, value);
node.setAttribute(name, '' + value);
} else if (__DEV__) {
warnUnknownProperty(name);
}
Expand Down
8 changes: 8 additions & 0 deletions src/dom/__tests__/DOMPropertyOperations-test.js
Expand Up @@ -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,
Expand Down

0 comments on commit b0455f4

Please sign in to comment.