Skip to content

Commit

Permalink
Fix wrong name printed in custom elements (when passed as props) (#46)
Browse files Browse the repository at this point in the history
* Fix wrong name printed in custom elements

* Update Node versions for Travis

* Use plain old function declaration for ReactElement test

* Fix test

* Update test.js
  • Loading branch information
guigrpa authored and cpojer committed Nov 1, 2016
1 parent eae0f2e commit 9214857
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "4"
- "5"
- "6"
12 changes: 12 additions & 0 deletions __tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,18 @@ describe('prettyFormat()', () => {
);
});

it('supports a single element with custom React elements with props', () => {
function Cat() {
return React.createElement('div');
};
assertPrintedJSX(
React.createElement('Mouse', {
prop: React.createElement(Cat, {foo: 'bar'})
}),
'<Mouse\n prop={\n <Cat\n foo="bar" />\n } />'
);
});

it('supports a single element with React elements with a child', () => {
assertPrintedJSX(
React.createElement('Mouse', {
Expand Down
9 changes: 8 additions & 1 deletion plugins/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ function printProps(props, print, indent, opts) {
}

function printElement(element, print, indent, opts) {
let result = '<' + element.type;
let result = '<';
if (typeof element.type === 'string') {
result += element.type;
} else if (typeof element.type === 'function') {
result += element.type.displayName || element.type.name || 'Unknown';
} else {
result += 'Unknown';
}
result += printProps(element.props, print, indent, opts);

const opaqueChildren = element.props.children;
Expand Down

0 comments on commit 9214857

Please sign in to comment.