Writing Tests
typescript
1// src/components/MyComponent/__tests__/MyComponent.test.tsx2import { render, screen } from '@testing-library/react';3import userEvent from '@testing-library/user-event';4import { axe, toHaveNoViolations } from 'jest-axe';5import { MyComponent } from '../MyComponent';67expect.extend(toHaveNoViolations);89describe('MyComponent', () => {10 it('renders with default props', () => {11 render(<MyComponent>Hello</MyComponent>);12 expect(screen.getByText('Hello')).toBeInTheDocument();13 });1415 it('has no accessibility violations', async () => {16 const { container } = render(<MyComponent>Hello</MyComponent>);17 const results = await axe(container);18 expect(results).toHaveNoViolations();19 });2021 it('supports keyboard navigation', async () => {22 const user = userEvent.setup();23 render(<MyComponent>Focusable</MyComponent>);24 await user.tab();25 expect(screen.getByText('Focusable')).toHaveFocus();26 });27});