Skip to content
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

Jest - toHaveStyleRule no longer works with css prop #250

Open
theboyWhoCriedWoolf opened this issue Jun 18, 2019 · 2 comments
Open

Jest - toHaveStyleRule no longer works with css prop #250

theboyWhoCriedWoolf opened this issue Jun 18, 2019 · 2 comments

Comments

@theboyWhoCriedWoolf
Copy link

theboyWhoCriedWoolf commented Jun 18, 2019

I have recently updated to the most recent styled-components & jest-styled-components. Now all previously working tests using toHaveStyleRule fail on all components that have their styles set using the css prop.

For example:

const StyledComp = styled('div')`
    // SOME STYLES
`

function SomeOtherComp(props) {
   return <StyledComp css="font-size: 20px;" { ...props } />
}

Within Jest now running the following fails and returns "font-size: undefined".

it('Should find the style', () => {
     const wrapper = renderer.create(<SomeOtherComp />).toJSON();
     expect(wrapper).toHaveStyleRule('font-size', '20px');
})
@ghost
Copy link

ghost commented Jun 19, 2019

I think we have raised a similar issue here:

#191

Although this has been closed we still have the same bug as labelled above.

@fabb
Copy link

fabb commented Jan 12, 2020

I also have this issue:

const MyComponent: FunctionComponent<{ className?: string }> = ({ className }) => <div className={className} />

const MyStyledComponent = styled(MyComponent)<{ position: string }>`
    position: ${p => p.position};
    border: none;
`

const MyWrapper: FunctionComponent<{}> = () => (
    <MyStyledComponent
        position="static"
        css={css`
            display: none;
        `}
    />
)

it('does not capture the css prop styles', () => {
    const { container } = renderWithProviders(<MyWrapper />)
    expect(container.firstChild).toMatchSnapshot()
})

The snapshot looks like this:

exports[`Grid does not capture the css prop styles 1`] = `
.c0 {
  position: static;
  border: none;
}

<div
  class="c0"
/>
`;

The display: none rule and class are missing from the snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants