-
Notifications
You must be signed in to change notification settings - Fork 384
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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'); | ||
| }); | ||
|
|
||
| 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.
Add regression coverage for
aria-labelledby+ defaultaria-labelcoexistence.These tests cover default and custom label values, but they don’t lock the third behavior this PR depends on: when only
aria-labelledbyis provided,aria-label="Contents"should still be present.Suggested test addition
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'); }); + +test('keeps default aria-label when aria-labelledby is provided', () => { + render(<Spinner aria-labelledby="external-label" />); + const spinner = screen.getByRole('progressbar'); + expect(spinner).toHaveAttribute('aria-labelledby', 'external-label'); + expect(spinner).toHaveAttribute('aria-label', 'Contents'); +});📝 Committable suggestion
🤖 Prompt for AI Agents