Skip to content

Commit

Permalink
feat: add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Monro committed May 4, 2019
1 parent 8437fc5 commit 31fca3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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),
}
}
Expand Down
21 changes: 19 additions & 2 deletions tests/queries.spec.js → tests/render.spec.js
Original file line number Diff line number Diff line change
@@ -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'}})

Expand All @@ -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))
})
})

0 comments on commit 31fca3a

Please sign in to comment.