-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 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
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,48 @@ | ||
import prettyFormat from 'pretty-format'; | ||
import { html } from 'htm/react'; | ||
import { prettyDOM } from '@testing-library/dom'; | ||
const { ReactElement } = prettyFormat.plugins; | ||
|
||
/** | ||
* Format a react element for printing to the dom | ||
*/ | ||
const format = (element: JSX.Element) => | ||
prettyFormat(element, { | ||
plugins: [ReactElement], | ||
printFunctionName: false, | ||
highlight: true, | ||
}); | ||
|
||
/** | ||
* Log a pretty html string | ||
* | ||
* @param html - the string to print | ||
*/ | ||
export const logHtml = (str: string) => { | ||
console.log( | ||
html` | ||
<div>${str}</div> | ||
`, | ||
); | ||
console.log( | ||
format( | ||
html` | ||
${str} | ||
`, | ||
), | ||
); | ||
}; | ||
|
||
/** | ||
* Log an element in a pretty way within the dom | ||
* | ||
* @param element - the element to print | ||
*/ | ||
export const logElement = (element: Node) => console.log(prettyDOM(element as HTMLElement)); | ||
|
||
/** | ||
* Log JSX in a pretty way | ||
* | ||
* @param jsx - the jsx to print | ||
*/ | ||
export const logJSX = (jsx: JSX.Element) => console.log(format(jsx)); |
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