-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.test.js
199 lines (176 loc) · 5.06 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const cssMatcher = require('jest-matcher-css')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
const defaultOptions = {
corePlugins: { preflight: false },
plugins: [require('../src')],
}
function run(input, config, plugin = tailwindcss) {
return postcss(
plugin(config)
)
.process(input, {
from: undefined
})
}
expect.extend({
toMatchCss: cssMatcher
})
it('should add the container query at-rule for `.cq-w-22` class and its contents', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="cq-w-22:bg-yellow-200"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
@container (min-width: 352px) {
.cq-w-22\:bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
}
`)
})
})
it('should add the container query at-rule for `.cq-h-22` class and its contents', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="cq-h-22:bg-yellow-200"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
@container (min-height: 352px) {
.cq-h-22\:bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
}
`)
})
})
it('should match the arbitrary values', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="cq-h-[450px]:bg-yellow-200 cq-w-[238px]:bg-yellow-200"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
@container (min-height: 450px) {
.cq-h-\[450px\]\:bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
}
@container (min-width: 238px) {
.cq-w-\[238px\]\:bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
}
`)
})
})
it('should add the `container-type-size` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-type-size"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-type-size {
container-type: size;
}
`)
})
})
it('should add the `container-type-inline-size` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-type-inline-size"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-type-inline-size {
container-type: inline-size;
}
`)
})
})
it('should add the `container-type-block-size` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-type-block-size"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-type-block-size {
container-type: block-size;
}
`)
})
})
it('should add the `container-type-style` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-type-style"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-type-style {
container-type: style;
}
`)
})
})
it('should add the `container-type-state` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-type-state"></div>` }],
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-type-state {
container-type: state;
}
`)
})
})
it('should create the `container-name-sidebar` class', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="container-name-sidebar"></div>` }],
theme: {
containerName: {
sidebar: 'sidebar'
}
},
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
.container-name-sidebar {
container-name: sidebar;
}
`)
})
})
it('should create a named container query at-rule', () => {
const config = {
...defaultOptions,
content: [{ raw: String.raw`<div class="cq-w-sd-22:bg-yellow-200"></div>` }],
theme: {
containerName: {
sd: 'sidebar'
}
},
}
return run('@tailwind utilities;', config).then((result) => {
expect(result.css).toMatchCss(String.raw`
@container sidebar (min-width: 352px) {
.cq-w-sd-22\:bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
}
`)
})
})