-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathdebug.js
42 lines (33 loc) · 1.09 KB
/
debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import HelloWorld from './components/HelloWorld'
import { cleanup, render } from '@testing-library/vue'
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {})
})
afterEach(() => {
cleanup()
console.log.mockRestore()
})
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')
)
})