Skip to content

Commit

Permalink
feat(debug): Add maxLength and options to debug (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
afontcu authored Nov 1, 2020
1 parent d356049 commit 920dff2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ test('debug pretty prints multiple nodes with the given parameter', () => {
expect.stringContaining('Lorem ipsum dolor sit amet'),
)
})

test('allows same arguments as prettyDOM', () => {
const {debug, container} = render(HelloWorld)

// debug accepts a maxLength and an options parameters:
// https://testing-library.com/docs/dom-testing-library/api-helpers#prettydom
debug(container, 6, {highlight: false})

expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`
Array [
<div>
...,
]
`)
})
8 changes: 5 additions & 3 deletions src/vue-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createLocalVue, mount} from '@vue/test-utils'

import {
getQueriesForElement,
logDOM,
prettyDOM,
waitFor,
fireEvent as dtlFireEvent,
} from '@testing-library/dom'
Expand Down Expand Up @@ -72,8 +72,10 @@ function render(
return {
container,
baseElement,
debug: (el = baseElement) =>
Array.isArray(el) ? el.forEach(e => logDOM(e)) : logDOM(el),
debug: (el = baseElement, maxLength, options) =>
Array.isArray(el)
? el.forEach(e => console.log(prettyDOM(e, maxLength, options)))
: console.log(prettyDOM(el, maxLength, options)),
unmount: () => wrapper.destroy(),
isUnmounted: () => wrapper.vm._isDestroyed,
html: () => wrapper.html(),
Expand Down

0 comments on commit 920dff2

Please sign in to comment.