forked from testing-library/react-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prettyDOM): Expose pretty-dom utility (testing-library#25)
* Expose pretty-dom utility * Allow users of prettyDOM to set max length * Remove logDOM * Add tests for prettyDOM * Add yarn-error.log to .gitignore * Add documencation for prettyDOM * Update pretty-dom.js
- Loading branch information
Showing
7 changed files
with
78 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`it prints out the given DOM element tree 1`] = ` | ||
"[36m<div>[39m | ||
[36m<div>[39m | ||
[0mHello World![0m | ||
[36m</div>[39m | ||
[36m</div>[39m" | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {prettyDOM} from '../pretty-dom' | ||
import {render} from './helpers/test-utils' | ||
|
||
test('it prints out the given DOM element tree', () => { | ||
const {container} = render('<div>Hello World!</div>') | ||
expect(prettyDOM(container)).toMatchSnapshot() | ||
}) | ||
|
||
test('it supports truncating the output length', () => { | ||
const {container} = render('<div>Hello World!</div>') | ||
expect(prettyDOM(container, 5)).toMatch(/\.\.\./) | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import prettyFormat from 'pretty-format' | ||
|
||
const {DOMElement, DOMCollection} = prettyFormat.plugins | ||
|
||
function prettyDOM(htmlElement, maxLength) { | ||
const debugContent = prettyFormat(htmlElement, { | ||
plugins: [DOMElement, DOMCollection], | ||
printFunctionName: false, | ||
highlight: true, | ||
}) | ||
return maxLength !== undefined && htmlElement.outerHTML.length > maxLength | ||
? `${debugContent.slice(0, maxLength)}...` | ||
: debugContent | ||
} | ||
|
||
export {prettyDOM} |
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