Cypress tests - Gewia/frontend GitHub Wiki

Important:

  • Please write for your created pages and components tests
  • Please look up here how to write them
  • Test your app before making a pull request

How to run the tests:

  • Start your localhost with npm start
  • To run all tests: npm run test:run
  • To open cypress and select a specific test: npm run test:open

Writing tests

Location:

  • Put all your tests under cypress/integration outside the srcfolder
  • Create for your test a new file with the schema: name.spec.js just replace name with your filename

Code:

  • Start your file with describe('description', () => {...} replace description with yours in lowercase
  • Inside this you can place multiple it('description', () => {...}
  • Inside this you can add some functions starting by cy and your function:
    • .get('element')[you can e.g. access a p tag or with a . a class ( be careful that a class can return an array )
    • .click() clicks on the element
    • .eq(index) gets the elment with the specific index from an array
    • .first() gets the first element form an array
    • .should('include', 'text') [replace text with yours], checks if a element includes text e.g. the url
    • .url() gets the url
    • .type('text') [replace text with your input], type the text in an input
    • .visit('url') [replace url with yours], navigate to the side but type for http://localhost:3000/ just /
    • you finde more under documentation

Example:

You will find an example here or a more complex one here