Skip to content
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

feat: export callbacks for hooks #1270

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: export callbacks for hooks #1270

wants to merge 2 commits into from

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Feb 3, 2025

What

Export @experimental functions prepare, reset and detach to improve support for different test environments.

import userEvent, {prepare, reset, detach } from '@testing-library/user-event'
import { beforeAll, afterEach, afterAll, test } from 'some-test-runner'
import { DomImplementation } from 'some-dom-implementation'

const window = new DomImplementation()

beforeAll(() => prepare(window))
afterEach(() => reset(window))
afterAll(() => detach(window))

test('something', async () => {
  const user = userEvent.setup({document: window.document})
  // ...

Why

UserEvent should work in various environments. Exposing these functions allows our users to integrate UserEvent in environments that don't use global hooks or global document.

How

Includes a fix to restoreFocus.

Includes a check if globalThis.window exists.

Checklist

  • Ready to be merged

Copy link

codesandbox-ci bot commented Feb 3, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant