menu

styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress!

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# Help
view-forward
# jest
view-forward
# Off Topic
view-forward
# Website
view-forward
Team

Testing createGlobalStyle in v5

January 19, 2020 at 3:02am

Testing createGlobalStyle in v5

January 19, 2020 at 3:02am (Edited 6 months ago)
Hi!
I am building a component library which has a component for global styles. In v4, the component was tested as follows:
GlobalStyles
import { createGlobalStyle } from 'styled-components';
const GlobalStyles = createGlobalStyle`
body {
height: 100vh;
margin: 0;
overflow: hidden;
width: 100vw;
}
`;
export default GlobalStyles;
Testing
import renderer from 'react-test-renderer';
import '@testing-library/jest-dom/extend-expect';
import 'jest-styled-components';
import GlobalStyles from './GlobalStyles.component';
it('renders default global styles', () => {
const css = renderer.create(GlobalStyles.globalStyle.rules).toJSON();
expect(css).toMatchSnapshot();
});
With the advent of v5, this seems to be not possible as globalStyle is undefined.
Does anyone know how to access the rules, so they can be tested?
No messages yet