Open
Description
@testing-library/jest-dom
version: v5.1.1@testing-library/react
version: v9.4.0node
version: v12.14.1npm
(oryarn
) version: v1.21.1
Relevant code or config:
import styled from 'styled-components';
const Container = styled.div`
visibility: hidden;
&:hover {
visibility: visible;
}
> input:checked {
visibility: visible;
}
`;
const { getByTestId } = render(
<Container>
<input data-testid="checkbox" type="checkbox" checked />
</Container>
);
expect(getByTestId('checkbox')).toBeVisible();
What you did:
Tried to test a checkbox that must be visible when it has been checked with toBeVisible
.
What happened:
Even though the checkbox is visible toBeVisible
throws an error because it detects that the parent has visibility: hidden
.
Reproduction:
https://codesandbox.io/s/kind-rain-62otm?fontsize=14&hidenavigation=1&previewwindow=tests&theme=dark
Problem description:
My code has a checkbox that must be visible when the user checks it. The visibility property is perfect for this because it overrides its parents' values.
So, if the checkbox has visibility: visible
property, it will be shown regardless of the parent value.
Suggested solution:
Not sure :( will come up with something if this is really an issue.