Skip to content

Commit 958ee89

Browse files
committed
test(Spinner): use toHaveAccessibleName and cover aria-labelledby coexistence
1 parent ffe889d commit 958ee89

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ test('simple spinner', () => {
88

99
test('uses default aria-label of "Contents" when none is provided', () => {
1010
render(<Spinner />);
11-
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Contents');
11+
expect(screen.getByRole('progressbar')).toHaveAccessibleName('Contents');
1212
});
1313

1414
test('uses a custom aria-label when one is provided', () => {
1515
render(<Spinner aria-label="Loading users" />);
16-
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users');
16+
expect(screen.getByRole('progressbar')).toHaveAccessibleName('Loading users');
17+
});
18+
19+
test('keeps the default aria-label when aria-labelledby is provided', () => {
20+
render(
21+
<>
22+
<span id="spinner-label">Loading reports</span>
23+
<Spinner aria-labelledby="spinner-label" />
24+
</>
25+
);
26+
27+
const spinner = screen.getByRole('progressbar');
28+
expect(spinner).toHaveAttribute('aria-label', 'Contents');
29+
expect(spinner).toHaveAttribute('aria-labelledby', 'spinner-label');
30+
expect(spinner).toHaveAccessibleName('Loading reports');
1731
});
1832

1933
test('small spinner', () => {

0 commit comments

Comments
 (0)