# Testing guidelines The goal of this document is to address the most frequently asked "How to" questions related to unit testing. ## Some recommended practices for testing - Default to the `*ByRole` queries when testing components because it encourages testing with accessibility concerns in mind. - Alternatively, you could use `*ByLabelText` queries for testing components. However, we recommend the `*ByRole` queries because they are [more robust](https://testing-library.com/docs/queries/bylabeltext/#name). ## 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. 1. 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(