-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(react-jss): added tests for createUseStyles
- Loading branch information
1 parent
59003b4
commit c967ea6
Showing
2 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,72 @@ | ||
/* eslint-disable react/prop-types */ | ||
import createUseStyles from './createUseStyles' | ||
import createBasicTests from '../test-utils/createBasicTests' | ||
|
||
const createStyledComponent = (styles, options) => { | ||
const useStyles = createUseStyles(styles, options) | ||
const Comp = props => { | ||
useStyles(props) | ||
return null | ||
} | ||
return Comp | ||
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', () => { | ||
createBasicTests({createStyledComponent}) | ||
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; | ||
} | ||
}`) | ||
}) | ||
}) |