From 31fca3a4c91c3864c9c803a4fe340161c1d02a57 Mon Sep 17 00:00:00 2001 From: Ben Monro Date: Fri, 3 May 2019 17:05:03 -0700 Subject: [PATCH] feat: add debug --- src/index.js | 4 +++- tests/{queries.spec.js => render.spec.js} | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) rename tests/{queries.spec.js => render.spec.js} (72%) diff --git a/src/index.js b/src/index.js index cce664a..fabf240 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import {getQueriesForElement} from 'dom-testing-library' +import {getQueriesForElement, prettyDOM} from 'dom-testing-library' export * from 'dom-testing-library' const mountedContainers = new Set() @@ -13,6 +13,8 @@ export const render = (Component, options) => { mountedContainers.add(component) return { component, + // eslint-disable-next-line no-console + debug: (el = document.body) => console.log(prettyDOM(el)), ...getQueriesForElement(document.body), } } diff --git a/tests/queries.spec.js b/tests/render.spec.js similarity index 72% rename from tests/queries.spec.js rename to tests/render.spec.js index 728139b..ecf9634 100644 --- a/tests/queries.spec.js +++ b/tests/render.spec.js @@ -1,9 +1,16 @@ -import {render, fireEvent, wait, waitForElement, cleanup} from '../src' +import { + render, + fireEvent, + wait, + waitForElement, + cleanup, + prettyDOM, +} from '../src' import App from './example/App.svelte' import 'jest-dom/extend-expect' afterEach(cleanup) -describe('queries', () => { +describe('render', () => { test('getByText', () => { const {getByText} = render(App, {props: {name: 'world'}}) @@ -29,4 +36,14 @@ describe('queries', () => { await wait(() => expect(getByText('Hello foo!')).toBeInTheDocument()) }) + + test('debug', () => { + global.console = {log: jest.fn()} + + const {debug} = render(App) + + debug() + + expect(global.console.log).toHaveBeenCalledWith(prettyDOM(document.body)) + }) })