-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
134 lines (127 loc) · 2.48 KB
/
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
const _ = require('lodash');
const cssMatcher = require('jest-matcher-css');
const postcss = require('postcss');
const tailwindcss = require('tailwindcss');
const aspectRatioPlugin = require('./index.js');
const generatePluginCss = (config) => {
return postcss(
tailwindcss(
_.merge({
theme: {
screens: {
'sm': '640px',
},
},
corePlugins: false,
plugins: [
aspectRatioPlugin,
],
}, config)
)
)
.process('@tailwind utilities', {
from: undefined,
})
.then(result => {
return result.css;
});
};
expect.extend({
toMatchCss: cssMatcher,
});
test('there is no output by default', () => {
return generatePluginCss().then(css => {
expect(css).toMatchCss(`
@media (min-width: 640px) {
}
`);
});
});
test('ratios can be customized', () => {
return generatePluginCss({
theme: {
aspectRatio: {
'2/1': [2, 1],
'16/9': [16, 9],
},
},
}).then(css => {
expect(css).toMatchCss(`
.aspect-ratio-2\\/1 {
padding-bottom: 50%;
}
.aspect-ratio-16\\/9 {
padding-bottom: 56.25%;
}
@media (min-width: 640px) {
.sm\\:aspect-ratio-2\\/1 {
padding-bottom: 50%;
}
.sm\\:aspect-ratio-16\\/9 {
padding-bottom: 56.25%;
}
}
`);
});
});
test('ratios can be arrays or fractions', () => {
return generatePluginCss({
theme: {
aspectRatio: {
'5/2': [5, 2],
'16/9': 16 / 9,
},
},
variants: {
aspectRatio: [],
},
}).then(css => {
expect(css).toMatchCss(`
.aspect-ratio-5\\/2 {
padding-bottom: 40%;
}
.aspect-ratio-16\\/9 {
padding-bottom: 56.25%;
}
`);
});
});
test('ratio can be 0', () => {
return generatePluginCss({
theme: {
aspectRatio: {
'none': 0,
},
},
variants: {
aspectRatio: [],
},
}).then(css => {
expect(css).toMatchCss(`
.aspect-ratio-none {
padding-bottom: 0;
}
`);
});
});
test('variants can be customized', () => {
return generatePluginCss({
theme: {
aspectRatio: {
'2/1': [2, 1],
},
},
variants: {
aspectRatio: ['hover'],
},
}).then(css => {
expect(css).toMatchCss(`
.aspect-ratio-2\\/1 {
padding-bottom: 50%;
}
.hover\\:aspect-ratio-2\\/1:hover {
padding-bottom: 50%;
}
`);
});
});