Skip to content

Commit 5cbf16b

Browse files
committed
Extract log-dom tests
They hide console logs which we shouldn't do for pretty-dom since that shouldn't console.log in the first place
1 parent 76cb73d commit 5cbf16b

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

src/__tests__/log-dom.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {getUserCodeFrame} from '../get-user-code-frame'
2+
import {logDOM} from '../pretty-dom'
3+
import {render} from './helpers/test-utils'
4+
5+
jest.mock('../get-user-code-frame')
6+
7+
beforeEach(() => {
8+
jest.spyOn(console, 'log').mockImplementation(() => {})
9+
})
10+
11+
afterEach(() => {
12+
console.log.mockRestore()
13+
})
14+
15+
test('logDOM logs prettyDOM to the console', () => {
16+
const {container} = render('<div>Hello World!</div>')
17+
logDOM(container)
18+
expect(console.log).toHaveBeenCalledTimes(1)
19+
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
20+
<div>
21+
<div>
22+
Hello World!
23+
</div>
24+
</div>
25+
`)
26+
})
27+
28+
test('logDOM logs prettyDOM with code frame to the console', () => {
29+
getUserCodeFrame.mockImplementationOnce(
30+
() => `"/home/john/projects/sample-error/error-example.js:7:14
31+
5 | document.createTextNode('Hello World!')
32+
6 | )
33+
> 7 | screen.debug()
34+
| ^
35+
"
36+
`,
37+
)
38+
const {container} = render('<div>Hello World!</div>')
39+
logDOM(container)
40+
expect(console.log).toHaveBeenCalledTimes(1)
41+
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
42+
<div>
43+
<div>
44+
Hello World!
45+
</div>
46+
</div>
47+
48+
"/home/john/projects/sample-error/error-example.js:7:14
49+
5 | document.createTextNode('Hello World!')
50+
6 | )
51+
> 7 | screen.debug()
52+
| ^
53+
"
54+
55+
`)
56+
})

src/__tests__/pretty-dom.js

+1-55
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import {prettyDOM, logDOM} from '../pretty-dom'
2-
import {getUserCodeFrame} from '../get-user-code-frame'
1+
import {prettyDOM} from '../pretty-dom'
32
import {render, renderIntoDocument} from './helpers/test-utils'
43

5-
jest.mock('../get-user-code-frame')
6-
7-
beforeEach(() => {
8-
jest.spyOn(console, 'log').mockImplementation(() => {})
9-
})
10-
11-
afterEach(() => {
12-
console.log.mockRestore()
13-
})
14-
154
test('prettyDOM prints out the given DOM element tree', () => {
165
const {container} = render('<div>Hello World!</div>')
176
expect(prettyDOM(container)).toMatchInlineSnapshot(`
@@ -58,49 +47,6 @@ test('prettyDOM supports receiving the document element', () => {
5847
`)
5948
})
6049

61-
test('logDOM logs prettyDOM to the console', () => {
62-
const {container} = render('<div>Hello World!</div>')
63-
logDOM(container)
64-
expect(console.log).toHaveBeenCalledTimes(1)
65-
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
66-
<div>
67-
<div>
68-
Hello World!
69-
</div>
70-
</div>
71-
`)
72-
})
73-
74-
test('logDOM logs prettyDOM with code frame to the console', () => {
75-
getUserCodeFrame.mockImplementationOnce(
76-
() => `"/home/john/projects/sample-error/error-example.js:7:14
77-
5 | document.createTextNode('Hello World!')
78-
6 | )
79-
> 7 | screen.debug()
80-
| ^
81-
"
82-
`,
83-
)
84-
const {container} = render('<div>Hello World!</div>')
85-
logDOM(container)
86-
expect(console.log).toHaveBeenCalledTimes(1)
87-
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
88-
<div>
89-
<div>
90-
Hello World!
91-
</div>
92-
</div>
93-
94-
"/home/john/projects/sample-error/error-example.js:7:14
95-
5 | document.createTextNode('Hello World!')
96-
6 | )
97-
> 7 | screen.debug()
98-
| ^
99-
"
100-
101-
`)
102-
})
103-
10450
describe('prettyDOM fails with first parameter without outerHTML field', () => {
10551
test('with array', () => {
10652
expect(() => prettyDOM(['outerHTML'])).toThrowErrorMatchingInlineSnapshot(

0 commit comments

Comments
 (0)