I am in the process of upgrading the dependencies of a React project. I upgraded styled-components from 1.4.4
to 2.5.0-1
. I didn't expect any breaking changes since I read that styled-components v2 is a drop-in replacement for v1.
I don't see any breaking changes in the web app, but my test cases are broken.
Consider the following, dumb and useless test.
test('does something', () => {
expect(true).toBe(true);
});
As expected, the test works. However, as soon as I even try to import a styled-component in the test file, it fails.
I added the following import.
import {Container} from './styled';
The Container styled-component is defined thus:
export const Container = styled.div`
width: 80%;
display: flex;
flex-direction: column;
transition: opacity 0.25s ease-in-out;
`;
I get the following error:
Cannot create styled-component for component: [object Object]
Right now, I fail to understand what's going on. Why can't I import a styled-component?
EDIT
The problem was with styled-components that import svg assets. See answer below.