diff --git a/.vscode/settings.json b/.vscode/settings.json index 3fe16e7..fc9601a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "standard.enable": false, "eslint.enable": true, - "eslint.autoFixOnSave": true, + "eslint.autoFixOnSave": false, "git.ignoreLimitWarning": true } diff --git a/src/utils.js b/src/utils.js index a148e84..d46655b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,10 @@ /* global Cypress */ const sd = require('@wildpeaks/snapshot-dom') +function isJqueryElement (x) { + return 'wrap' in x +} + // converts DOM element to a JSON object function serializeDomElement ($el) { // console.log('snapshot value!', $el) @@ -17,23 +21,23 @@ function serializeDomElement ($el) { return json } -const stripAttribute = (attribute) => (el$) => { - el$.removeAttr(attribute) - el$.children().each(stripAttribute(attribute)) - return el$ +const stripReactIdAttributes = html => { + const dataReactId = /data\-reactid="[\.\d\$\-abcdfef]+"/g + return html.replace(dataReactId, '') } -const serializeReactToHTML = (el$) => { - const copy$ = Cypress.$(el$.outerHTML) - const removedReactId = stripAttribute('data-reactid')(copy$) - return removedReactId.html() +const serializeReactToHTML = el$ => { + debugger + const html = el$[0].outerHTML + const stripped = stripReactIdAttributes(html) + return stripped } -const identity = (x) => x +const identity = x => x -const publicProps = (name) => !name.startsWith('__') +const publicProps = name => !name.startsWith('__') -const countSnapshots = (snapshots) => +const countSnapshots = snapshots => Object.keys(snapshots).filter(publicProps).length module.exports = { @@ -42,5 +46,5 @@ module.exports = { serializeReactToHTML, identity, countSnapshots, - stripAttribute + isJqueryElement }