-
Notifications
You must be signed in to change notification settings - Fork 391
fix(Spinner): define default aria-label via destructuring #12420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bd7e869
ffe889d
958ee89
fc9e371
a0e3104
c3e7514
7b4b254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,26 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Spinner } from '../Spinner'; | ||
|
|
||
| test('simple spinner', () => { | ||
| const { asFragment } = render(<Spinner />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('uses default aria-label of "Contents" when none is provided', () => { | ||
| render(<Spinner />); | ||
| expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Contents'); | ||
| }); | ||
|
|
||
| test('uses a custom aria-label when one is provided', () => { | ||
| render(<Spinner aria-label="Loading users" />); | ||
| expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above here |
||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test('renders aria-labelledBy when provided', () => { | ||
| render(<Spinner aria-labelledBy="external-label" />); | ||
| expect(screen.getByRole('progressbar')).toHaveAttribute('aria-labelledBy', 'external-label'); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New test codifies the pre-existing The prop and assertion both use The test will pass today (JSDOM stores ✅ Corrected test (aligned with WAI-ARIA spec) test('renders aria-labelledBy when provided', () => {
- render(<Spinner aria-labelledBy="external-label" />);
- expect(screen.getByRole('progressbar')).toHaveAttribute('aria-labelledBy', 'external-label');
+ render(<Spinner aria-labelledby="external-label" />);
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-labelledby', 'external-label');
});The full fix also requires renaming the prop in 🤖 Prompt for AI Agents |
||
|
|
||
| test('small spinner', () => { | ||
| const { asFragment } = render(<Spinner size="sm" />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: we should use
toHaveAccessibleNameinstead here