Skip to content

Commit b41805a

Browse files
committed
Allow debug() to accept a DOM parameter
1 parent d2accd9 commit b41805a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/vue-testing-library.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function render (TestComponent, {
6464
return {
6565
container: wrapper.element.parentNode,
6666
baseElement: document.body,
67-
debug: () => console.log(prettyDOM(wrapper.element)),
67+
debug: (el = wrapper.element) => console.log(prettyDOM(el)),
6868
unmount: () => wrapper.destroy(),
6969
isUnmounted: () => wrapper.vm._isDestroyed,
7070
html: () => wrapper.html(),
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<template>
2-
<div>Hello World!</div>
2+
<div>
3+
<h1>Hello World!</h1>
4+
<p>Lorem ipsum dolor sit amet</p>
5+
</div>
36
</template>

tests/__tests__/debug.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@ afterEach(() => {
1010
console.log.mockRestore()
1111
})
1212

13-
test('debug pretty prints the container', () => {
13+
test('debug pretty prints the container if no parameter is provided', () => {
1414
const { debug } = render(HelloWorld)
15+
1516
debug()
17+
18+
expect(console.log).toHaveBeenCalledTimes(1)
19+
expect(console.log).toHaveBeenCalledWith(
20+
expect.stringContaining('Hello World')
21+
)
22+
expect(console.log).toHaveBeenCalledWith(
23+
expect.stringContaining('Lorem ipsum dolor sit amet')
24+
)
25+
})
26+
27+
test('debug pretty prints the provided parameter', () => {
28+
const { getByText, debug } = render(HelloWorld)
29+
30+
// debug accepts a DOM node as a parameter.
31+
debug(getByText('Lorem ipsum dolor sit amet'))
32+
1633
expect(console.log).toHaveBeenCalledTimes(1)
1734
expect(console.log).toHaveBeenCalledWith(
35+
expect.stringContaining('Lorem ipsum dolor sit amet')
36+
)
37+
38+
// Notice the 'not' particle
39+
expect(console.log).not.toHaveBeenCalledWith(
1840
expect.stringContaining('Hello World')
1941
)
2042
})

0 commit comments

Comments
 (0)