0
0
Cypresstesting~5 mins

cypress-testing-library - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is cypress-testing-library used for?
It helps you write tests that find elements the way users do, by their text or role, making tests easier to read and maintain.
Click to reveal answer
beginner
How does cypress-testing-library improve test selectors compared to CSS selectors?
It encourages using queries like findByRole or findByText that match what users see, instead of fragile CSS selectors that can break easily.
Click to reveal answer
beginner
What command do you use to install cypress-testing-library?
Run npm install --save-dev @testing-library/cypress to add it to your project.
Click to reveal answer
intermediate
How do you add cypress-testing-library commands to Cypress?
Import <code>@testing-library/cypress/add-commands</code> in your <code>cypress/support/e2e.js</code> file to enable its commands.
Click to reveal answer
intermediate
Give an example of using cypress-testing-library to find a button by its role and click it.
Example:<br>cy.findByRole('button', { name: /submit/i }).click()<br>This finds a button with accessible name 'submit' and clicks it.
Click to reveal answer
Which command is provided by cypress-testing-library to find elements by their accessible role?
AquerySelector
BgetByClass
CfindByRole
DgetById
What is the main benefit of using cypress-testing-library selectors over CSS selectors?
AThey match user-visible text or roles, making tests more reliable
BThey are faster to run
CThey require less code
DThey only work with buttons
Where should you import @testing-library/cypress/add-commands in your Cypress project?
Acypress/plugins/index.js
Bcypress/support/e2e.js
Ccypress.json
Dpackage.json
Which of these is a valid way to find a button with the text 'Submit' using cypress-testing-library?
Acy.findByRole('button', { name: /submit/i })
Bcy.findById('submit')
Ccy.get('button.submit')
Dcy.findByText('Submit')
What does the cy.findByText() command do?
AFinds elements by their CSS class
BFinds elements by their HTML tag
CFinds elements by their ID
DFinds elements containing specific visible text
Explain how cypress-testing-library helps improve the reliability and readability of Cypress tests.
Think about how users find elements on a page.
You got /4 concepts.
    Describe the steps to set up cypress-testing-library in a new Cypress project.
    Focus on installation and configuration.
    You got /3 concepts.