Closed
Description
@testing-library/jest-dom
version: 5.11.0node
version: 12.17.0npm
(oryarn
) version: 6.14.4
Relevant code or config:
test('div max-width', () => {
const div = document.createElement('div');
div.style.maxWidth = '300px';
div.style.minWidth = '200px';
expect(div).toHaveStyle({ minWidth: '200px', maxWidth: '' }); // passes, but it should not
});
I expect that this assertion will fail, because maxWidth
is not empty.
It works, when I am using toEqual
instead of toHaveStyle
expect(div.style).toEqual(expect.objectContaining({ minWidth: '200px', maxWidth: '' }));
Suggested solution:
Somehow this information about empty values is lost around these lines:
Lines 60 to 61 in 7ea936d
A potential fix would be to check that all keys are from the expectation are defined on the element style definition.