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

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

Open
ghost opened this issue Sep 12, 2022 · 1 comment
Labels
new rule New rule to be included in the plugin

Comments

@ghost
Copy link

ghost commented Sep 12, 2022

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

@ghost ghost added new rule New rule to be included in the plugin triage Pending to be triaged by a maintainer labels Sep 12, 2022
@Belco90
Copy link
Member

Belco90 commented Sep 12, 2022

Thanks for your suggestion @pc-snatesan! It looks like a nice suggestion for the latest user-event version (we would have to mention that in the docs). A few clarifications:

  • The rule name shouldn't contain uppercase, so it should be prefer-user-event-setup
  • user-event actually applies to all frameworks supported by this plugin, not just the react one!

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new rule New rule to be included in the plugin
Projects
None yet
Development

No branches or pull requests

1 participant