-
-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react-jss): Media query styles applied only to the first element in function #1343
Open
pranshuchittora
wants to merge
2
commits into
cssinjs:master
Choose a base branch
from
pranshuchittora:pc/fix/react-jss/dynamicSheet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; | ||
} | ||
}`) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this test should be applied to both hook and hoc based implementation, just to be sure both work same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pls elaborate, like exactly which components are needed to be tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createBasicTests() is the function that runs all the tests which use the passed function which creates a styled component. You picked the test file that only serves as an entry point to generate tests using hooks interface,
If we want to run the test with both interfaces, you need to add the test inside createBasicTests
Also it seems like you removed createBasicTests() call entirely from this file, which means you don't run all the tests using hooks interface at all now