You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, the bug is caused because the class names are influenced by the order in which the styled components are created. This is an unfortunate necessity, since we have nothing else to uniquely identify which component is which at runtime. So, doing this doesn't break the tests:
import styled from 'styled-components';
-// export const Bar = styled.div``;-
export default styled.div`
color: blue;
`;
++export const Bar = styled.div``;
because Bar comes after export default so the order is unchanged.
The real solution is to use the babel transform in test, which bakes in unchanging component IDs instead of relying on runtime ordering. Also, the plugin to use is babel-plugin-styled-components rather than babel-plugin-styled-components-named. Here's the full diff of what I got working:
So, the bug is caused because the class names are influenced by the order in which the styled components are created. This is an unfortunate necessity, since we have nothing else to uniquely identify which component is which at runtime. So, doing this doesn't break the tests:
because
Bar
comes afterexport default
so the order is unchanged.The real solution is to use the babel transform in test, which bakes in unchanging component IDs instead of relying on runtime ordering. Also, the plugin to use is
babel-plugin-styled-components
rather thanbabel-plugin-styled-components-named
. Here's the full diff of what I got working:The text was updated successfully, but these errors were encountered: