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

Export UserEvent type #1085

Closed
brandon-leapyear opened this issue Dec 14, 2022 · 3 comments
Closed

Export UserEvent type #1085

brandon-leapyear opened this issue Dec 14, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@brandon-leapyear
Copy link

Problem description

The docs mention that one can wrap userEvent.setup() in a setup function and return it alongside the render result. But adding a type signature to setup is difficult because there's no easy way to reference the return type of userEvent.setup().

Suggested solution

Ideally, I'd like to be able to do

import { render, RenderOptions, RenderResult } from '@testing-library/react'
import userEvent, { UserEvent } from '@testing-library/user-event'

const setup = (options: RenderOptions): RenderResult & { user: UserEvent } => ({
  ...render(options),
  user: userEvent.setup(),
})

Additional context

Current workaround:

type UserEvent = ReturnType<typeof userEvent.setup>
@brandon-leapyear brandon-leapyear added enhancement New feature or request needs assessment This needs to be looked at by a team member labels Dec 14, 2022
@mattrunyon
Copy link

mattrunyon commented Jan 9, 2023

Another use case is if I want to create a test util for certain series of events (like control clicking)

async function controlClick(user: UserEvent, element: HTMLElement) {
  await user.keyboard('{Control>}');
  await user.click(element);
  await user.keyboard('{/Control}');
}

@ph-fritsche ph-fritsche removed the needs assessment This needs to be looked at by a team member label Mar 14, 2023
This was referenced Mar 30, 2023
@Moto42
Copy link

Moto42 commented Jul 11, 2023

I've been importing it as...
import { UserEvent } from "@testing-library/user-event/dist/types/setup/setup";

Which allows for
let user:UserEvent;

@joshuajaco
Copy link
Contributor

@kentcdodds this one can also be closed.
Was fixed in #1112

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

No branches or pull requests

6 participants