Skip to content
Discussion options

You must be logged in to vote

Good afternoon. In my opinion, the main advantage of userEvent.setup() is that it creates a reusable instance of a user event that shares the input device's state.
For example:
const user = userEvent.setup()

await user.keyboard('[ShiftLeft>]')
await user.click(button)

In this case, the click retains the keyboard state from the previous interaction, just as it would during a real user interaction.

With direct API calls, such as userEvent.click(), setup() is invoked internally for each call. This makes the direct API convenient for simple tests, but separate calls don't share the same input device state.

Using setup() also makes it possible to configure an instance once and reuse it through…

Replies: 1 comment 2 replies

Comment options

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

@Valeriia458
Comment options

Answer selected by snowystinger
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