Skip to content

Is there some guidance on when to use setup() vs userEvent.whatever? #1036

Answered by ph-fritsche
camjackson asked this question in Q&A
Discussion options

You must be logged in to vote

This exists to ease the transition to version 14 and writing simple tests. Using the methods on the instances returned by userEvent.setup() is recommended.

This pretty much sums it up.
You should use userEvent.setup() after creating the document and before you render() your component.
You can keep on using the direct APIs if rewriting tests is to much work on a project or if you only write a simple (throw-away) test.

In almost all cases it will not make a difference, but if you hit one of the rare edge cases, it might be hard to debug - especially since most environments don't create a new document for each test. So the first test will apply .setup() after rendering and every subsequent…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@camjackson
Comment options

@neriyarden
Comment options

Answer selected by camjackson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants