Skip to content

useFocusVisible crashes in tests with @testing-library/user-event + Vitest/jsdom #9649

@onlywei

Description

@onlywei

Provide a general summary of the issue here

When loading any component that loads @react-aria/interactions under the hood (like Button), we get the error:

TypeError: Cannot set property focus of [object HTMLElement] which has only a getter

This happens when userEvent.setup() is used in the unit test:

import { userEvent } from '@testing-library/user-event';

const user = userEvent.setup();

See repro.

🤔 Expected Behavior?

I expect to be able to use testing-library's user events to click around without error.

😯 Current Behavior

The error below immediately occurs as soon as the @react-aria/interactions module is loaded:

TypeError: Cannot set property focus of [object HTMLElement] which has only a getter

💁 Possible Solution

Not sure if this is fixable here or whether it needs to be fixed in testing-library

🔦 Context

No response

🖥️ Steps to Reproduce

See this repro: https://github.com/onlywei/repro-react-aria-vitest-focus#

Version

react-aria-components@1.15.1

What browsers are you seeing the problem on?

Other

If other, please specify.

vitest jsdom

What operating system are you using?

MacOS 15.5

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions