Skip to content

Commit

Permalink
test(datepicker): add UT for aria attr added during invalid state
Browse files Browse the repository at this point in the history
  • Loading branch information
clukhei committed Apr 22, 2024
1 parent 5016739 commit 3a770b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/DatePicker/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2198,4 +2198,23 @@ describe('Datepicker a11y', () => {
});
expect(container.querySelector('input')).toHaveFocus();
});
it('when state is invalid, input aria-invalid=true, aria-describedby points to Feedback', async () => {
const { container, getByText } = render(<DatePicker />);

const input = container.querySelector('input')!;
expect(input.getAttribute('aria-describedby')).toEqual('');
expect(input.getAttribute('aria-invalid')).toEqual('false');
fireEvent.change(input, { target: { value: '01132024' } });
fireEvent.blur(input);
// Triggering invalid state
await waitFor(() => {
expect(getByText('Please enter a valid date')).toBeInTheDocument();
});
const feedbackId = getByText('Please enter a valid date').getAttribute(
'id'
);

expect(input.getAttribute('aria-invalid')).toEqual('true');
expect(input.getAttribute('aria-describedby')).toEqual(feedbackId);
});
});

0 comments on commit 3a770b9

Please sign in to comment.