Skip to content

Commit

Permalink
[New] Debug: debugNode now returns [function] for function children
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored and ljharb committed Jul 2, 2018
1 parent 2c28e6c commit 9745de0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/enzyme-test-suite/test/Debug-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -748,5 +748,35 @@ describe('debug', () => {
</Foo>`
));
});

it('handles function children', () => {
class Abomination extends React.Component {
render() {
/* eslint no-unused-vars: 0, func-names: 0 */
return (
<div>
{function Foo() { /* hi */ }}
{<span />}
{arrow => arrow('function')}
{[1, 2, NaN]}
{function (anonymous) {}}
</div>
);
}
}

const wrapper = shallow(<Abomination />);
expect(wrapper.debug()).to.equal((
`<div>
[function Foo]
<span />
[function]
1
2
NaN
[function]
</div>`
));
});
});
});
4 changes: 4 additions & 0 deletions packages/enzyme/src/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function indentChildren(childrenStrs, indentLength) {

export function debugNode(node, indentLength = 2, options = {}) {
if (typeof node === 'string' || typeof node === 'number') return escape(node);
if (typeof node === 'function') {
const name = functionName(node);
return `[function${name ? ` ${name}` : ''}]`;
}
if (!node) return '';

const childrenStrs = compact(childrenOfNode(node).map(n => debugNode(n, indentLength, options)));
Expand Down

0 comments on commit 9745de0

Please sign in to comment.