Open
Description
@testing-library/jest-dom
version: 5.11.6node
version: v14.15.1npm
(oryarn
) version: 1.22.10svelte-testing-library
version: 3.0.0
Relevant code or config:
:root {
--font-size-xlarge: 64px;
--font-weight-bold: 700;
}
.title {
font-size: var(--font-size-xlarge);
font-weight: var(--font-weight-bold);
margin: auto 0;
}
<div data-testid="title" class="title">Title</div>
const search = getByTestId('search');
expect(title).toHaveStyle({
'font-size': 'var(--font-size-xlarge)',
'font-weight': 'var(--font-weight-bold)',
});
What you did:
Test font style w/ @testing-library/jest-dom
and @testing-library/svelete-testing-library
What happened:
Test should fail if i set font-size
not as var(--font-size-xlarge)
, but test still passes.
But works charm about font-weight.
expect(element).toHaveStyle()
- Expected
- font-size: ;
- font-weight: var(--font-weight-light);
+ font-weight: var(--font-weight-bold);
33 | const settings = getByTestId('settings');
34 |
> 35 | expect(title).toHaveStyle({
| ^
36 | 'font-size': 'var(--font-size-xlarge)',
37 | 'font-weight': 'var(--font-weight-light)',
38 | });
Reproduction:
from this commit,
install w/ yarn
then run test w/ yarn test
Problem description:
Seems like cannot recognize font-size with css variable, as we can see the result of getComputedStyle(title)
below
CSSStyleDeclaration {
'0': 'display',
'1': 'font-weight',
'2': 'margin',
'3': 'visibility',
_values: {
display: 'block',
'font-weight': 'var(--font-weight-bold)',
margin: 'auto 0px',
'margin-top': 'auto',
'margin-right': '0px',
'margin-bottom': 'auto',
'margin-left': '0px',
visibility: 'visible'
},
_importants: {
display: '',
'font-size': '',
'font-weight': '',
margin: '',
visibility: undefined
},
_length: 4,
_onChange: [Function (anonymous)]
}