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

toHaveStyleRule should intelligently ignore spaces in strings

Open danielmariz opened this issue 4 years ago • 2 comments
trafficstars

I am having the same issue as described in Issue#89

the value is correct but somehow the styled-components remove all spaces in the value and does not get strictly compared to the same value passed

` "Value mismatch for property 'font-family'"

Expected
  "font-family: europa, -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif"
Received:
  "font-family: europa,-apple-system,system-ui,BlinkMacSystemFont,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,sans-serif"

> 72 |                 expect(Node).toHaveStyleRule('font-family', text.heading.fontFamily)

`

Versions: "styled-components": "^5.2.3" "jest-styled-components": "^7.0.3"

danielmariz avatar Jul 29 '21 22:07 danielmariz

to get around it I had to do this ugly solution expect(Node).toHaveStyleRule('font-family', text.heading.fontFamily!.split(', ').join(','))

danielmariz avatar Jul 29 '21 22:07 danielmariz

Similar issue, in my case I was getting:

Expected (This is actually what I was sending, it was pretty confusing)
      "background-color: rgb(24, 107, 237)"
    Received: (This is what was actually expected)
      "background-color: rgb(24,107,237)"

For me to get it working I had to do something different

value.toString().replace(/\s/g, '');

Termtime avatar May 09 '22 15:05 Termtime