-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
134 lines (131 loc) · 2.86 KB
/
index.test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* eslint-env jest */
const serializerFactory = require('./index')
describe('test with different option combinations', () => {
const styles = `
${/* full match */''}
#container {
color: magenta;
}
${/* partial match */''}
#container-container > #container {
color: purple;
transform: scale(.5);
}
${/* each part of the selector will be on a separate line
in the snapshot; some of them are partial matches */''}
ul li.aa,
body > section li.bb,
#container li:not(li) {
opacity: .5;
}
${/* should have a mediaText property in the snapshot */''}
@media (max-width: 599px) {
ul,
li + li:nth-child(2n) {
font-size: 12px;
padding: 20px;
margin: 30px;
}
}
`
const html = `
<div id="container">
<div class="xx">
<ul class="yy">
<li class="aa"></li>
<li class="bb">
<span>no css for me</span>
</li>
<li class="cc"></li>
</ul>
</div>
</div>
`
const options = {
recursive: false,
includeHtml: false,
includeCss: false,
includeCssHash: false,
includePartialMatches: false
}
const findMatches = serializerFactory(styles, options, expect)
function executeFindMatchesTest (message, options) {
it(message, async () => {
expect(await findMatches(html, options)).toMatchSnapshot()
})
}
executeFindMatchesTest(
'all options === false',
{}
)
executeFindMatchesTest(
'recursive === true',
{
recursive: true
}
)
// using "recursive" so the snapshots will have more data
executeFindMatchesTest(
'includePartialMatches === true',
{
recursive: true,
includePartialMatches: true
}
)
executeFindMatchesTest(
'includeHtml === true',
{
recursive: true,
includeHtml: true
}
)
executeFindMatchesTest(
'includeCss === true',
{
recursive: true,
includeCss: true
}
)
executeFindMatchesTest(
'includeCssHash === true',
{
recursive: true,
includeCssHash: true
}
)
executeFindMatchesTest(
'includeCssHash takes precedence over includeCss',
{
includeCss: true,
includeCssHash: true
}
)
})
describe('html with multiple root elements', () => {
it('create a snapshot with multiple roots', async () => {
const html = `
<div></div>
<div>
<div></div>
</div>
<div></div>
<div>
<span></span>
<span></span>
</div>
`
const styles = `
div {
color: red;
}
`
const options = {
recursive: true,
includeHtml: true,
includeCssHash: true,
includePartialMatches: false
}
const findMatches = serializerFactory(styles, options, expect)
expect(await findMatches(html, options)).toMatchSnapshot()
})
})