-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
strict-property-values.test.ts
171 lines (148 loc) · 3.68 KB
/
strict-property-values.test.ts
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
import { assertType, describe, test } from 'vitest'
import { css } from '../../styled-system-strict-property-values/css'
describe('css', () => {
test('native CSS prop and value', () => {
assertType(css({ display: 'flex' }))
// @ts-expect-error expected from strictPropertyValues: true
assertType(css({ display: 'abc' }))
assertType(css({ content: 'abc' }))
assertType(css({ willChange: 'abc' }))
assertType(css({ pos: 'absolute' }))
// @ts-expect-error always expected
assertType(css({ pos: 'absolute123' }))
assertType(css({ flex: '0 1' }))
assertType(css({ borderTop: '1px solid red' }))
// @ts-expect-error expected
assertType(css({ borderTopStyle: 'aaa' }))
})
test('token value', () => {
assertType(css({ color: 'blue.300' }))
})
test('css var', () => {
assertType(css({ color: 'var(--button-color)' }))
assertType(css({ display: 'var(--button-color)' }))
})
test('utility prop', () => {
assertType(
css({
srOnly: true,
}),
)
})
test('shorthand prop', () => {
assertType(
css({
backgroundColor: 'red',
bg: 'red',
}),
)
})
test('object condition prop', () => {
assertType(css({ bg: { _hover: 'yellow.100' } }))
})
test('condition prop', () => {
assertType(css({ _hover: { bg: 'yellow.200' } }))
})
test('nested condition prop', () => {
assertType(
css({
_hover: {
_dark: {
bg: 'pink',
},
},
}),
)
})
test('arbitrary value', () => {
assertType(
css({
color: '#fff',
}),
)
})
test('arbitrary value escape hatch', () => {
assertType(
css({
color: '[#fff]',
fontSize: '[123px]',
}),
)
})
test('arbitrary value escape hatch with conditionals', () => {
assertType(
css({
color: '[#fff]',
fontSize: '[123px]',
bgColor: '[#fff!]',
borderColor: '[#fff !important]',
_hover: {
color: '[#fff]',
fontSize: '[123px]',
bgColor: '[#fff!]',
borderColor: '[#fff !important]',
},
backgroundColor: {
_dark: '[#3B00B9]',
_hover: '[#3B00B9!]',
_focus: '[#3B00B9 !important]',
},
}),
)
})
test('arbitrary selector', () => {
assertType(css({ ['&:data-panda']: { display: 'flex' } }))
})
test('important', () => {
assertType(
css({
fontSize: '2xl!',
p: '4 !important',
bgColor: '#fff!',
bg: '#fff!',
borderColor: '#fff !important',
_hover: {
fontSize: '2xl!',
p: '4 !important',
bgColor: '#fff!',
borderColor: '#fff !important',
},
backgroundColor: {
_disabled: '2xl!',
_active: '4 !important',
_hover: '#3B00B9!',
_focus: '#3B00B9 !important',
},
}),
)
})
test('responsive condition', () => {
assertType(
css({
sm: {
bg: 'purple',
},
}),
)
})
test('responsive array syntax prop', () => {
assertType(
css({
bg: ['cyan.100', 'cyan.200', null, undefined, 'cyan.300'],
}),
)
})
test('using inline token helper - in value', () => {
assertType(
css({
border: '1px solid token(colors.blue.400)',
}),
)
})
test('using inline token helper - in condition', () => {
assertType(css({ '@media screen and (min-width: token(sizes.4xl))': { bg: 'blue.500' } }))
})
test('nested condition prop with array syntax', () => {
assertType(css({ _hover: { _dark: { bg: ['pink.100', 'pink.200'] } } }))
})
})