Skip to content

Commit 31fca3a

Browse files
author
Ben Monro
committed
feat: add debug
1 parent 8437fc5 commit 31fca3a

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Diff for: src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getQueriesForElement} from 'dom-testing-library'
1+
import {getQueriesForElement, prettyDOM} from 'dom-testing-library'
22

33
export * from 'dom-testing-library'
44
const mountedContainers = new Set()
@@ -13,6 +13,8 @@ export const render = (Component, options) => {
1313
mountedContainers.add(component)
1414
return {
1515
component,
16+
// eslint-disable-next-line no-console
17+
debug: (el = document.body) => console.log(prettyDOM(el)),
1618
...getQueriesForElement(document.body),
1719
}
1820
}

Diff for: tests/queries.spec.js renamed to tests/render.spec.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import {render, fireEvent, wait, waitForElement, cleanup} from '../src'
1+
import {
2+
render,
3+
fireEvent,
4+
wait,
5+
waitForElement,
6+
cleanup,
7+
prettyDOM,
8+
} from '../src'
29
import App from './example/App.svelte'
310
import 'jest-dom/extend-expect'
411

512
afterEach(cleanup)
6-
describe('queries', () => {
13+
describe('render', () => {
714
test('getByText', () => {
815
const {getByText} = render(App, {props: {name: 'world'}})
916

@@ -29,4 +36,14 @@ describe('queries', () => {
2936

3037
await wait(() => expect(getByText('Hello foo!')).toBeInTheDocument())
3138
})
39+
40+
test('debug', () => {
41+
global.console = {log: jest.fn()}
42+
43+
const {debug} = render(App)
44+
45+
debug()
46+
47+
expect(global.console.log).toHaveBeenCalledWith(prettyDOM(document.body))
48+
})
3249
})

0 commit comments

Comments
 (0)