Skip to content

Commit

Permalink
[New] RSTTraversal: add getHTMLFromHostNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 15, 2019
1 parent ebdd4e7 commit 8d4262b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/enzyme/src/RSTTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,18 @@ export function getTextFromHostNodes(node, adapter) {
},
});
}

export function getHTMLFromHostNodes(node, adapter) {
if (node === null) return null;

const hostNode = adapter.nodeToHostNode(node, true);
if (hostNode === null) return null;

const nodeArray = Array.isArray(hostNode) ? hostNode : [hostNode];
const nodesHTML = nodeArray.map(item => (item === null
? null
: item.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g, '')
));

return nodesHTML.join('');
}

0 comments on commit 8d4262b

Please sign in to comment.