Is there some guidance on when to use setup()
vs userEvent.whatever
?
#1036
-
I've been using testing-library and user-event for a few years. I've always done I recently started on a new team and have found that they do
I had never seen this before, went and did a bunch of reading, including this page of the docs, and some of the issues + PRs discussing the implementation. It seems that I find
What I really want to know is: if I'm not doing tricky multi-step interactions or trying to configure userEvent to do anything special, is there any reason to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This pretty much sums it up. 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 Yes, boilerplate in every test can be messy. A You can write a test helper that allows you to create single-line arrange steps in your tests. |
Beta Was this translation helpful? Give feedback.
This pretty much sums it up.
You should use
userEvent.setup()
after creating the document and before yourender()
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…