testing-library/jest-dom

toHaveStyle for property `font-size` behaves incorrectly for number values

Open

#564 ouverte le 27 déc. 2023

Voir sur GitHub
 (2 commentaires) (1 réaction) (0 assignés)JavaScript (416 forks)github user discovery
buggood first issue

Métriques du dépôt

Stars
 (4 594 stars)
Métriques de merge PR
 (Métriques PR en attente)

Description

  • @testing-library/jest-dom version: 6.1.5
  • node version: 20.3.1
  • jest (or vitest) version: 0.34.1
  • npm (or yarn) version: 9.6.7

Relevant code or config:

render(<div data-testid="element" style={{ fontSize: 8 }} />)
expect(screen.getByTestId('element')).toHaveStyle({ fontSize: 1 })

What you did:

I expected the above assertion to fail

What happened:

The test passes instead!✅

Reproduction:

Problem description:

the assertion is clearly incorrect and can easily cause bugs

Suggested solution:

I have not thought of a solution yet but would like to investigate this issue during my off hours.

Guide contributeur