# Testing Guidelines The goal of this document is to address the most frequently asked "How to" questions related to unit testing. ## Best practices - Default to the `*ByRole` queries when testing components as it encourages testing with accessibility concerns in mind. It's also possible to use `*ByLabelText` queries. However, the `*ByRole` queries are [more robust](https://testing-library.com/docs/queries/bylabeltext/#name) and are generally recommended over the former. ## Testing User Interactions We use the [user-event](https://testing-library.com/docs/user-event/intro) library for simulating user interactions during testing. This library is preferred over the built-in `fireEvent` method, as it more accurately mirrors real user interactions with elements. There are two important considerations when working with `userEvent`: 1. All methods in `userEvent` are asynchronous, and thus require the use of `await` when called. 2. Directly calling methods from `userEvent` may not be supported in future versions. As such, it's necessary to first call `userEvent.setup()` prior to the tests. This method returns a `userEvent` instance, complete with all its methods. This setup process can be simplified using a utility function: ```tsx import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; function setup(jsx: JSX.Element) { return { user: userEvent.setup(), ...render(jsx), }; } it('should render', async () => { const { user } = setup(