Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5efe597

Browse files
authored
Merge pull request #39 from afontcu/master
Allow debug() to accept a parameter
2 parents c2ae9b8 + b58d8ff commit 5efe597

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

‎src/vue-testing-library.js‎

Lines changed: 1 addition & 1 deletion
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(),
Lines changed: 4 additions & 1 deletion
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‎

Lines changed: 23 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /