Skip to content

Allow debug() to accept a parameter #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vue-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function render (TestComponent, {
return {
container: wrapper.element.parentNode,
baseElement: document.body,
debug: () => console.log(prettyDOM(wrapper.element)),
debug: (el = wrapper.element) => console.log(prettyDOM(el)),
unmount: () => wrapper.destroy(),
isUnmounted: () => wrapper.vm._isDestroyed,
html: () => wrapper.html(),
Expand Down
5 changes: 4 additions & 1 deletion tests/__tests__/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<template>
<div>Hello World!</div>
<div>
<h1>Hello World!</h1>
<p>Lorem ipsum dolor sit amet</p>
</div>
</template>
24 changes: 23 additions & 1 deletion tests/__tests__/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,33 @@ afterEach(() => {
console.log.mockRestore()
})

test('debug pretty prints the container', () => {
test('debug pretty prints the container if no parameter is provided', () => {
const { debug } = render(HelloWorld)

debug()

expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Hello World')
)
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Lorem ipsum dolor sit amet')
)
})

test('debug pretty prints the provided parameter', () => {
const { getByText, debug } = render(HelloWorld)

// debug accepts a DOM node as a parameter.
debug(getByText('Lorem ipsum dolor sit amet'))

expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Lorem ipsum dolor sit amet')
)

// Notice the 'not' particle
expect(console.log).not.toHaveBeenCalledWith(
expect.stringContaining('Hello World')
)
})