-
Notifications
You must be signed in to change notification settings - Fork 1
Testing
giggity-hub edited this page Aug 3, 2023
·
2 revisions
# Run all tests in command line
npx cypress run
# Open the Cypress App
npx cypress open
# Run single spec
npx cypress run --spec "cypress/e2e/my-spec.cy.js"
You can query the Database in a cypress test by using the db:query
task
cy.task('db:query', 'SELECT * FROM users')
The db:query
Task expects only one Argument which is the "baked" query text.
Any Test which interacts with the database should reseed it before testing.
cy.task('db:reseed')
The db:reseed
task expects no arguments and executes all queries inside cypress/seed.sql
To avoid nasty css selectors and to decouple representation from functionality use data attributes on elements which you want to select and cy.getByData()
to select them.
<button data-test="register-button">Register User</button>
cy.getByData('register-button')
Cypress lets us define custom commands inside the cypress/support/commands.ts like getByData
and reset
.