Skip to content

Recommend using the methods on the instances returned by userEvent.setup() from userEvent #646

Open
@ghost

Description

Name for new rule

prefer-userEvent-setup

Description of the new rule

Rule should recommend using the methods on the instances returned by userEvent.setup() from userEvent as inline or using setup functions.

Testing Library feature

Enforce using the methods on the instances returned by userEvent.setup()

Testing Library framework(s)

React

What category of rule is this?

Suggests an alternate way of doing something

Optional: other category of rule

No response

Code examples

// inlining
test('trigger some awesome feature when clicking the button', async () => {
const user = userEvent.setup()
render()

await user.click(screen.getByRole('button', {name: /click me!/i}))

// ...assertions...
})

// setup function
function setup(jsx) {
return {
user: userEvent.setup(),
...render(jsx),
}
}

test('render with a setup function', async () => {
const {user} = setup()
// ...
})

Anything else?

No response

Do you want to submit a pull request to make the new rule?

Yes, but need help

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needednew ruleNew rule to be included in the plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions