forked from testing-library/react-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebug.js
55 lines (48 loc) · 1.3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react'
import {render, screen} from '../'
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {})
})
afterEach(() => {
console.log.mockRestore()
})
test('debug pretty prints the container', () => {
const HelloWorld = () => <h1>Hello World</h1>
const {debug} = render(<HelloWorld />)
debug()
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Hello World'),
)
})
test('debug pretty prints multiple containers', () => {
const HelloWorld = () => (
<>
<h1 data-testid="testId">Hello World</h1>
<h1 data-testid="testId">Hello World</h1>
</>
)
const {debug} = render(<HelloWorld />)
const multipleElements = screen.getAllByTestId('testId')
debug(multipleElements)
expect(console.log).toHaveBeenCalledTimes(2)
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Hello World'),
)
})
test('allows same arguments as prettyDOM', () => {
const HelloWorld = () => <h1>Hello World</h1>
const {debug, container} = render(<HelloWorld />)
debug(container, 6, {highlight: false})
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`
[
<div>
...,
]
`)
})
/*
eslint
no-console: "off",
*/