jest-styled-components icon indicating copy to clipboard operation
jest-styled-components copied to clipboard

v7.0.1 toHaveStyleRule not working with styled.svg

Open wadeharrell opened this issue 5 years ago • 2 comments

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);
    });
});

wadeharrell avatar Apr 07 '20 18:04 wadeharrell

PR welcome if you want to help debug!

quantizor avatar Apr 09 '20 04:04 quantizor

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

wadeharrell avatar Apr 09 '20 12:04 wadeharrell