Enhancing Cypress commands with the Cypress Testing Library
In the previous section, we learned how to install and write a user flow test using Cypress. In this section, we will learn how to install and configure the Cypress Testing Library to add enhanced query selectors. The Cypress Testing Library will allow us to use DOM Testing Library query methods in Cypress. Install the library using the following command:
npm install --save-dev @testing-library/cypress
The preceding code installs @testing-library/cypress
as a development dependency in your project. After the library is installed, we can add it to the Cypress commands
file:
import '@testing-library/cypress/add-commands'
In the preceding code, we extended the Cypress commands with those from the Cypress Testing Library. Now that we have the Cypress Testing Library installed, we can use it in our tests. It should be noted that only findBy*
methods from the DOM Testing Library are included to support the...