Skip to content

Commit

Permalink
[enzyme-adapter-utils] elementToTree: back compat: support naive ma…
Browse files Browse the repository at this point in the history
…pping
  • Loading branch information
ljharb committed Aug 18, 2018
1 parent 691d21c commit 892d368
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function elementToTree(el) {
const { children } = props;
let rendered = null;
if (isArrayLike(children)) {
rendered = flatten([...children]).map(el => elementToTree(el));
rendered = flatten([...children]).map(elementToTree);
} else if (typeof children !== 'undefined') {
rendered = elementToTree(children);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/enzyme-adapter-utils/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export function ensureKeyOrUndefined(key) {
}

export function elementToTree(el, recurse = elementToTree) {
if (typeof recurse !== 'function' && arguments.length === 3) {
// special case for backwards compat for `.map(elementToTree)`
recurse = elementToTree; // eslint-disable-line no-param-reassign
}
if (el === null || typeof el !== 'object' || !('type' in el)) {
return el;
}
Expand Down

0 comments on commit 892d368

Please sign in to comment.