-
-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathcreateUseStyles.test.js
More file actions
72 lines (65 loc) · 1.72 KB
/
createUseStyles.test.js
File metadata and controls
72 lines (65 loc) · 1.72 KB
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
/* eslint-disable react/prop-types */
import expect from 'expect.js'
import React from 'react'
import TestRenderer from 'react-test-renderer'
import {stripIndent} from 'common-tags'
import {SheetsRegistry, JssProvider, ThemeProvider, createUseStyles} from '.'
const createGenerateId = () => {
let counter = 0
return rule => `${rule.key}-${counter++}`
}
const theme: Object = {
background: 'yellow',
background2: 'red'
}
describe('React-JSS: createUseStyles', () => {
it('should render multiple elements with applied media query', () => {
const registry = new SheetsRegistry()
const useStyles = createUseStyles(themeObj => ({
wrapper: () => ({
padding: 40,
background: themeObj.background,
textAlign: 'left',
'@media (min-width: 1024px)': {
backgroundColor: themeObj.background2
}
})
}))
const Comp = () => {
const classes = useStyles(theme)
return <div className={classes.wrapper} />
}
const a = [1, 2]
TestRenderer.create(
<JssProvider registry={registry} generateId={createGenerateId()}>
<ThemeProvider theme={theme}>
{a.map(item => (
<Comp key={item} />
))}
</ThemeProvider>
</JssProvider>
)
expect(registry.toString()).to.be(stripIndent`
.wrapper-0 {}
.wrapper-d0-1 {
padding: 40px;
background: yellow;
text-align: left;
}
@media (min-width: 1024px) {
.wrapper-d0-1 {
background-color: red;
}
}
.wrapper-d1-2 {
padding: 40px;
background: yellow;
text-align: left;
}
@media (min-width: 1024px) {
.wrapper-d1-2 {
background-color: red;
}
}`)
})
})