Skip to content

Commit

Permalink
[Fix] debug: print String objects as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning authored and ljharb committed Dec 22, 2017
1 parent 5b5439a commit 8533b5e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1"
}
}
}
5 changes: 5 additions & 0 deletions packages/enzyme-test-suite/test/Debug-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ describe('debug', () => {
))).to.equal('<div id="foo" />');
});

it('should render a boxed String object as a string', () => {
expect(debugElement((
<div className={Object('foo')} />
))).to.equal('<div className="foo" />');
});
});

describeWithDOM('debugInst(inst)', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/enzyme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cheerio": "^1.0.0-rc.2",
"function.prototype.name": "^1.0.3",
"has": "^1.0.1",
"is-string": "^1.0.4",
"is-subset": "^0.1.1",
"lodash": "^4.17.4",
"object-is": "^1.0.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/enzyme/src/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import without from 'lodash/without';
import escape from 'lodash/escape';
import compact from 'lodash/compact';
import functionName from 'function.prototype.name';
import isString from 'is-string';

import {
propsOfNode,
Expand Down Expand Up @@ -32,6 +33,9 @@ function propString(prop) {
case 'boolean':
return `{${prop}}`;
case 'object':
if (isString(prop)) {
return `"${prop}"`;
}
return '{{...}}';
default:
return `{[${typeof prop}]}`;
Expand Down

0 comments on commit 8533b5e

Please sign in to comment.