-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
toHaveStyleRule TypeError: Cannot read property '1' of null #26
Comments
I was able to get passing test with it: import styled, { css } from 'styled-components' // ^2.0.0
import { mount } from 'enzyme' // ^2.8.2
import 'jest-styled-components' // 3.0.0
test('enzyme', () => {
const StyledLabel = styled.label`
display: block;
${props => props.horizontal && css`
display: inline;
`}
& i {
color: red;
}
${props => props.css}
`
const wrapper = mount(<StyledLabel horizontal>Hello World</StyledLabel>)
expect(wrapper).toHaveStyleRule('display', 'inline')
}) Maybe try |
I'm just rerun your test (the only thing I add is import of React at the top, cause it argues without it) |
I noticed the same thing today when I was updating my tests. I have a fix for this, but I'm not 100% sure what is causing it. Currently trying to reproduce this so I'll be able to send a PR. |
I have put together a small repository for reproduction at: https://github.com/jjanssen/jest-styled-components-example. In this repository is example with a css helper (Example) and just a plain component (Example2). Both of them are tested with Locally I also applied the change as proposed in PR #27 but this does not yet solve the issue. Right now it feels like the matching of the regular expression is not correct, although I'm not completely sure since I'm not too familiar with the styled-components internals. |
Thank you very much @jjanssen, your repo is exactly what we needed. |
I'm trying to test whether the component has
display:inline
when horizontal is set to true.Here is the component code:
And here is the test:
But at the end I got an error:
I have
"jest-styled-components": "^3.0.0"
and"styled-components": "^2.0.0"
and latest CRA.The text was updated successfully, but these errors were encountered: