Skip to content

Export UserEvent type #1085

Closed
Closed
@brandon-leapyear

Description

@brandon-leapyear

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions