jest-styled-components
jest-styled-components copied to clipboard
v7.0.1 toHaveStyleRule not working with styled.svg
Test is passing on 7.0.0, upgrade to 7.0.1 and it starts failing. It is is the only test to start failing, and it is the only instance of styled.svg in the code. Testing for width and height values, so pretty basic stuff.
const StyledSvg = styled.svg`
width: ${(props) => props.width};
height: ${(props) => props.height};
`;
const Foo = ({ width, height }) => {
return (
<StyledSvg width={width} height={height} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
<circle cx="25" cy="25" r="25" fill="none" />
</StyledSvg>
);
};
describe('Foo', () => {
const width = '40px';
const height = '40px';
const wrapper = shallow(<Foo width={width} height={height} />);
it('should have width style', () => {
expect(wrapper).toHaveStyleRule('width', width);
});
});
PR welcome if you want to help debug!
debugging so far: after this line https://github.com/styled-components/jest-styled-components/blob/master/src/toHaveStyleRule.js#L18 I added
console.log(`received.debug():${JSON.stringify(received.debug(),null,' ')}`);
console.log(`received.dive().debug():${JSON.stringify(received.dive().debug(),null,' ')}`);
the className values are not the same, which means the new hasClassName(received) condition is getting a different result than the typeof received.exists === "function" && received.exists() does