-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcx.test.js
125 lines (110 loc) Β· 2.6 KB
/
cx.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
import 'test-utils/setup-env'
import React from 'react'
import renderer from 'react-test-renderer'
import { css, cx } from '@emotion/css'
describe('cx', () => {
test('merge 2', () => {
const cls1 = css`
font-size: 20px;
background: green;
`
const tree = renderer.create(<div className={cx(cls1, 'modal')} />).toJSON()
expect(tree).toMatchSnapshot()
})
test('merge 3', () => {
const cls1 = css`
font-size: 20px;
background: green;
`
const cls2 = css`
font-size: 20px;
background: blue;
`
const tree = renderer
.create(<div className={cx(cls1, cls2, 'modal')} />)
.toJSON()
expect(tree).toMatchSnapshot()
})
test('merge 4', () => {
const cls1 = css`
font-size: 20px;
background: green;
`
const cls2 = css`
font-size: 20px;
background: blue;
`
const tree = renderer
.create(<div className={cx(cls1, cls2, 'modal', 'profile')} />)
.toJSON()
expect(tree).toMatchSnapshot()
})
test('all types', () => {
const cls1 = css`
font-size: 20px;
background: green;
`
const cls2 = css`
font-size: 20px;
background: blue;
`
const cls3 = css`
font-size: 20px;
background: darkorange;
`
const cls4 = css`
font-size: 20px;
background: darkgreen;
`
const foo = true
const bar = false
const tree = renderer
.create(
<div
className={cx({ [cls1]: foo }, 'modal', { [cls2]: bar }, 'profile', [
[cls3, [cls4]]
])}
/>
)
.toJSON()
expect(tree).toMatchSnapshot()
})
test('fun fun functions', () => {
const cls1 = css`
font-size: 20px;
background: green;
`
const cls2 = css`
font-size: 20px;
background: blue;
`
const cls3 = css`
font-size: 20px;
background: darkorange;
`
const cls4 = css`
font-size: 20px;
background: darkgreen;
`
const tree = renderer
.create(
<div
className={cx([
[cls1, false && cls2, 'modal'],
[cls3, { [cls4]: true }, 'profile']
])}
/>
)
.toJSON()
expect(tree).toMatchSnapshot()
})
test('no extra whitespace', () => {
expect(cx('blockquote', '', 'news')).toMatchSnapshot()
expect(cx('', 'group', '', 'news', '')).toMatchSnapshot()
expect(cx('author', '')).toMatchSnapshot()
expect(cx({ someClass: true, '': true })).toMatchSnapshot()
expect(
cx({ someClass: true, '': true, anotherClass: true })
).toMatchSnapshot()
})
})