Skip to content

Commit f2805d4

Browse files
danieljcafonsoKent C. Dodds
authored and
Kent C. Dodds
committed
feat(debug): allow debugging an array of containers (#495)
1 parent 594f858 commit f2805d4

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/__tests__/debug.js

+17
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ test('debug pretty prints the container', () => {
1919
)
2020
})
2121

22+
test('debug pretty prints multiple containers', () => {
23+
const HelloWorld = () => (
24+
<>
25+
<h1 data-testid="testId">Hello World</h1>
26+
<h1 data-testid="testId">Hello World</h1>
27+
</>
28+
)
29+
const {getAllByTestId, debug} = render(<HelloWorld />)
30+
const multipleElements = getAllByTestId('testId')
31+
debug(multipleElements)
32+
33+
expect(console.log).toHaveBeenCalledTimes(2)
34+
expect(console.log).toHaveBeenCalledWith(
35+
expect.stringContaining('Hello World'),
36+
)
37+
})
38+
2239
/* eslint no-console:0 */

src/pure.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ function render(
6060
return {
6161
container,
6262
baseElement,
63-
// eslint-disable-next-line no-console
64-
debug: (el = baseElement) => console.log(prettyDOM(el)),
63+
debug: (el = baseElement) =>
64+
Array.isArray(el)
65+
? // eslint-disable-next-line no-console
66+
el.forEach(e => console.log(prettyDOM(e)))
67+
: // eslint-disable-next-line no-console,
68+
console.log(prettyDOM(el)),
6569
unmount: () => ReactDOM.unmountComponentAtNode(container),
6670
rerender: rerenderUi => {
6771
render(wrapUiIfNeeded(rerenderUi), {container, baseElement})

0 commit comments

Comments
 (0)