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,
"eslint.enable": true,
"eslint.autoFixOnSave": true,
"eslint.autoFixOnSave": false,
"git.ignoreLimitWarning": true
}

View file

@ -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
}