Last active
December 16, 2022 04:27
-
-
Save sidouglas/3505fbeda6b5d8924496746366252bfe to your computer and use it in GitHub Desktop.
React Testing Library Dump Component html to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dump to your desktop the contents of a component at a point in time | |
// htmlDump(component); | |
function htmlDump(component: RenderResult) { | |
const fs = require('fs'); | |
const path = require('path'); | |
const os = require('os'); | |
const rtl = require('react-testing-library'); | |
const dir = os.homedir() + '/Desktop/htmlDump'; | |
if (!fs.existsSync(dir)) { | |
fs.mkdirSync(dir); | |
} | |
const scriptName = path.basename(__filename) + '.' + Date.now() + '.html'; | |
const data = rtl.prettyDOM(component.baseElement, undefined, { | |
highlight: false | |
})!; | |
fs.writeFile(`${dir}/${scriptName}`, data, { encoding: 'utf-8' }, err => { | |
err && console.log(err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment