-
Notifications
You must be signed in to change notification settings - Fork 7
Create a single repo for all the testing solutions related to Styled Components #2
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
Comments
Hi Michele, |
Sure, the new package (or packages) is going to have all the same features (and potentially more). |
Cool 🎉, Testing styled components would be more awesome! |
Awesome! Maybe we could solve #1 directly in the new package?
I thought a little about it and that makes sense, it is semantically correct to pass options to the matcher. So, we might have a signature like:
Also, if we want to test css API, do you think that a signature like this might be ok?
I'm not totally sure about the last one... But I have no other ideas at the moment.
Yeah, I totally agree with you, it gives the package a kind of personality. nailed is great 😄 P.S. |
I'm glad to help. @mbasso I love that right now this repo has many features supported for modifiers, media, pseudos already! I understand that https://github.com/mbasso/styled-components-test-utils already supports using toHaveStyleRule with enzyme's api or not? as seen in https://github.com/mbasso/styled-components-test-utils/blob/master/src/matchers/toHaveStyleRule.js#L23 (but docs says not 😂 ). I've seen you used the component's I think combining modifier, media as one object should be more easier to add new things. @MicheleBertoli Right now, If creating enhancements for https://github.com/styled-components/jest-styled-components how would it be aligned in the end? I'll follow up this topic and see what I can do. 👍 |
@yanawaro I'd try to avoid using Enzyme's internals (e.g. |
@yanawaro Thank you! I'm happy that we'll work together on this project 😄 @MicheleBertoli thank you, I'll write to you the 10th of august! |
@MicheleBertoli I'm back, we can talk about the project :) |
Welcome back @mbasso, I hope you enjoyed your holidays. |
Thank you! Yeah, I really needed them. What do you think about this? |
I totally agree with you, @yanawaro recently added the third Next things I'd like to do:
Unfortunately, I'm a bit busy until the end of the month because I'm preparing a talk, but let's keep discussing and sharing ideas. |
I'll try to write my thoughts, let me know what do you think supported environments/libsAt the moment styled-components-test-utils supports jest, expect, chai and jasmine. I'd like to add ava but it seems that it cannot be extended at the moment, the same for tape. APIs, matchersStarting from our 2 libs, here is the list of matchers: // test styled components: https://www.styled-components.com/docs/api#styled
expect(tree: reactElement).toHaveStyleRule(selector: string, value: string | number | RegExp, options?: {
modifier?: string,
media?: string | object,
});
// test css api: https://www.styled-components.com/docs/api#css
expect(css).toHaveStyleRule(selector: string, value: string | number | RegExp, options?: {
modifier?: string,
media?: string | object,
props?: object,
});
// test keyframes api: https://www.styled-components.com/docs/api#keyframes
expect(keyframe: string).toHaveKeyframeRule(keyframeSelector: string, selector: string, value: string);
// test injectGlobal api: https://www.styled-components.com/docs/api#injectglobal
expect(style: string).toBeAGlobalStyle();
// snapshot
expect(tree: reactElement).toMatchSnapshot();
// examples
// toHaveStyleRule
const Example = styled.div`
padding: 2em 1em;
background: papayawhip;
&:hover {
background: palevioletred;
}
@media (max-width: 600px) {
background: tomato;
&:hover {
background: yellow;
}
}
> p {
text-decoration: underline;
}
html.test & {
display: none;
}
`;
const component = renderer.create(<Example />);
expect(component).toHaveStyleRule('background', 'papayawhip');
// pseudo selectors
expect(component).toHaveStyleRule('background', 'palevioletred', {
modifier: ':hover', // or '&:hover'
});
// descendant-selectors
expect(component).toHaveStyleRule('text-decoration', 'underline', {
modifier: '> p',
});
// contextual selectors
expect(component).toHaveStyleRule('display', 'none', {
modifier: 'html.test &',
});
// media as string
expect(component).toHaveStyleRule('background', 'tomato', {
media: '(max-width: 600px)',
});
// media as object
// it should be thought of as if it is the current state of a device/browser.
// a type value must be specified, and it can not be "all".
// The returned rule is the one applied under those conditions
expect(component).toHaveStyleRule('background', 'tomato', {
media: {
type: 'screen',
width: '700px',
},
});
expect(component).toHaveStyleRule('background', 'papayawhip', {
media: {
type: 'screen',
width: '400px',
},
});
const style = css`
color: ${props => props.primary ? props.primary : 'white'}
`;
expect(style).toHaveStyleRule('color', 'black', {
props: {
primary: 'black',
},
});
// toHaveKeyframeRule
const fadeIn = keyframes`
0% {
opacity: 0;
}
100% {
opacity: 1;
}
`;
expect(fadeIn).toHaveKeyframeRule('0%', 'opacity', '0');
// toBeAGlobalStyle
injectGlobal`
input {
font-family: Roboto;
}
`;
expect(`
input {
font-family: Roboto;
}
`).toBeAGlobalStyle();
// toMatchSnapshot
const tree = renderer.create(<MyComponent />).toJSON();
expect(tree).toMatchSnapshot(); I have only one problem with theme, I don't know how we can avoid to do this in each test: const component = <Button theme={theme} />; single VS multiple packagesI think that a single package might look like this library, users have to do something like: import 'styled-components-test-utils/jest';
// or, for example, import 'styled-components-test-utils/chai'; With multiple packages the repo will be better organized and less confusing for users, they will be able to install directly the right package.
setupWill you create the repo (nailed) under the org? Can we also setup and use travis and coveralls? I think that we can use the MIT license and the Contributor Covenant Code of Conduct |
This is awesome, thanks @mbasso. |
Awesome! Let me know when you are ready 😄 |
I'm so so so sorry but I just realized I don't have the capacity to start a new project anytime soon. |
This project forked an older version of jest-styled-components and provides some of the same functionalities with different APIs, which generates confusion for the users.
Why don't we "merge" the projects (under the org I guess) and create a single repo for all the testing solutions related to Styled Components?
We could use Lerna to manage dependencies and packages.
Let me know if you are interested.
The text was updated successfully, but these errors were encountered: