Skip to content

Testing

giggity-hub edited this page Aug 3, 2023 · 2 revisions

Shell Commands

# 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"

Database Integration

Making Queries

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.

Reseeding the Database

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

Best Practices

Use cy.getByData to select DOM-Elements

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 Commands

Cypress lets us define custom commands inside the cypress/support/commands.ts like getByData and reset.