Vitest Browser Mode Locators - The Modifier Functions

When you query for elements with functions like getByRole() or getByText(), they return a Locator object.

Normally that is all you will need for querying specific elements in your tests. However, there will be times when selecting elements needs a bit more filtering or specificity.

There are several modifier methods that you can call on the Locator object to refine the query, like nth(0) or first() (both get the first element), and() to combine two Locator matches, or filter() to filter a specific element from a list.

Knowing and understanding them is very important for writing correct tests that are easy to read.

In this lesson, we will cover them and how to use them.

Loading full lesson...