Skip to content

Amazing new locators in 2.1 beta don't seem to work with the interactivity API #6449

@xeger

Description

@xeger

Describe the bug

Also filed as vitest/vitest-browser-react#1 but I am cross posting here for visibility purposes.

It seems that @vitest/browser/context isn't properly coordinating with vitest-browser-react. The React rendering and verification work well by themselves, but when I try to fire any user events, the userEvent imported from @vitest/browser/context fails with an error.

Seems like the two pieces of @vitest/browser aren't communicating with ech other. (I know that vitest-browser-react is a separate package, but it integrates tightly with @vitest/browser, and in this case, the integration seems to be not quite right.)

Troubleshooting

👎 Tried swapping the order of render vs. setup
👎 Tried const user = userEvent; in case the setup is unnecessary

Reproduction

import { page, userEvent } from '@vitest/browser/context';
import { beforeEach, describe, expect, test } from 'vitest';

test('reproduction', () => {
  const user = userEvent.setup();
  const screen = page.render(<span>hello, world</span>);
  await user.hover(page.getByRole('button'));
});

This results in:

reproduction
Error: Could not determine window of node. Node was [object Object]
 - /src/__tests__/reproduction.test.tsx:7:2

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.79 GB / 36.00 GB
    Shell: 3.7.0 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.11.0 - ~/.asdf/installs/nodejs/20.11.0/bin/node
    npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 128.0.6613.114
    Chrome Canary: 130.0.6694.0
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.3.1 
    @vitest/browser: 2.1.0-beta.6 => 2.1.0-beta.6 
    @vitest/coverage-istanbul: 2.1.0-beta.6 => 2.1.0-beta.6 
    @vitest/runner: 2.1.0-beta.6 => 2.1.0-beta.6 
    vite: ^5.2.0 => 5.4.2 
    vitest: 2.1.0-beta.6 => 2.1.0-beta.6

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp4-importantViolate documented behavior or significantly improves performance (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions