adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
13.04k stars 1.13k forks source link

Getting warning to use aria-label when running tests when test markup is correct. #7056

Closed BMCwebdev closed 1 month ago

BMCwebdev commented 1 month ago

Provide a general summary of the issue here

I am getting the warning If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility However, even if I set the test up to use only React Aria Components, and in the correct setup, I still get the warning.

๐Ÿค” Expected Behavior?

Should not be giving the warning.

๐Ÿ˜ฏ Current Behavior

Is giving the warning.

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

I am using Vitest and @testing-library/react

๐Ÿ–ฅ๏ธ Steps to Reproduce

import React from 'react';
import { describe, it, expect, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import { Header, Section, ListBox } from 'react-aria-components';

afterEach(() => {
  cleanup();
});

describe('Test Component', () => {
  it('renders without warning', () => {
    render(
      <ListBox>
        <Section>
          <Header>Content</Header>
        </Section>
      </ListBox>,
    );
    expect(screen.getByText('Content')).toBeInTheDocument();
  });
});

Version

I am using React-Aria-Components

What browsers are you seeing the problem on?

Firefox

If other, please specify.

This is in my IDE (VSCode)

What operating system are you using?

Mac 14

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

reidbarber commented 1 month ago

The ListBox itself needs an aria-label. The Header suffices for the Section, but not the entire ListBox.

yihuiliao commented 1 month ago

Closing as a non-issue. If you're still having problems, feel free to reopen.