working on stripping react id

This commit is contained in:
Gleb Bahmutov 2017-12-10 13:53:49 -05:00
parent 7683fe3678
commit fb79175620
2 changed files with 17 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{ {
"standard.enable": false, "standard.enable": false,
"eslint.enable": true, "eslint.enable": true,
"eslint.autoFixOnSave": true, "eslint.autoFixOnSave": false,
"git.ignoreLimitWarning": true "git.ignoreLimitWarning": true
} }

View file

@ -1,6 +1,10 @@
/* global Cypress */ /* global Cypress */
const sd = require('@wildpeaks/snapshot-dom') const sd = require('@wildpeaks/snapshot-dom')
function isJqueryElement (x) {
return 'wrap' in x
}
// converts DOM element to a JSON object // converts DOM element to a JSON object
function serializeDomElement ($el) { function serializeDomElement ($el) {
// console.log('snapshot value!', $el) // console.log('snapshot value!', $el)
@ -17,23 +21,23 @@ function serializeDomElement ($el) {
return json return json
} }
const stripAttribute = (attribute) => (el$) => { const stripReactIdAttributes = html => {
el$.removeAttr(attribute) const dataReactId = /data\-reactid="[\.\d\$\-abcdfef]+"/g
el$.children().each(stripAttribute(attribute)) return html.replace(dataReactId, '')
return el$
} }
const serializeReactToHTML = (el$) => { const serializeReactToHTML = el$ => {
const copy$ = Cypress.$(el$.outerHTML) debugger
const removedReactId = stripAttribute('data-reactid')(copy$) const html = el$[0].outerHTML
return removedReactId.html() 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 Object.keys(snapshots).filter(publicProps).length
module.exports = { module.exports = {
@ -42,5 +46,5 @@ module.exports = {
serializeReactToHTML, serializeReactToHTML,
identity, identity,
countSnapshots, countSnapshots,
stripAttribute isJqueryElement
} }