From 6b9c2dcf827d1402fe70cae60e92ef2e9a2477d3 Mon Sep 17 00:00:00 2001 From: danieljcafonso Date: Thu, 3 Oct 2019 19:12:14 +0100 Subject: [PATCH] feat(debug): allow debugging an array of containers --- src/__tests__/debug.js | 17 +++++++++++++++++ src/pure.js | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/__tests__/debug.js b/src/__tests__/debug.js index 4cab1ea9..ad3b8591 100644 --- a/src/__tests__/debug.js +++ b/src/__tests__/debug.js @@ -19,4 +19,21 @@ test('debug pretty prints the container', () => { ) }) +test('debug pretty prints multiple containers', () => { + const HelloWorld = () => ( + <> +

Hello World

+

Hello World

+ + ) + const {getAllByTestId, debug} = render() + const multipleElements = getAllByTestId('testId') + debug(multipleElements) + + expect(console.log).toHaveBeenCalledTimes(2) + expect(console.log).toHaveBeenCalledWith( + expect.stringContaining('Hello World'), + ) +}) + /* eslint no-console:0 */ diff --git a/src/pure.js b/src/pure.js index 4565074b..1b1838bf 100644 --- a/src/pure.js +++ b/src/pure.js @@ -60,8 +60,12 @@ function render( return { container, baseElement, - // eslint-disable-next-line no-console - debug: (el = baseElement) => console.log(prettyDOM(el)), + debug: (el = baseElement) => + Array.isArray(el) + ? // eslint-disable-next-line no-console + el.forEach(e => console.log(prettyDOM(e))) + : // eslint-disable-next-line no-console, + console.log(prettyDOM(el)), unmount: () => ReactDOM.unmountComponentAtNode(container), rerender: rerenderUi => { render(wrapUiIfNeeded(rerenderUi), {container, baseElement})