Post/Code

HomeAboutUsesNow

Useful Cypress Tip.

I am a huge fan of Cypress!

For someone that had never done end-to-end testing before, I find it both familiar, and intuitive. Which is not the feeling I have while unit testing. Admittedly, using React Testing Library feels more intuitive to me since it is more focused on how the application will be used by the end user than in "units", which often feels like testing implementation details and not "functionality". Considering my front-end background, I think it just feels more natural to me to conceptualise of tests that work the way in which someone would use the application.

Regardless, a tip I picked up recently was that you can set the base url for the application in your cypress.json file as follows:

{
    "baseUrl": "http://localhost:3000"
}

This will then enable you to use urls in Cypress like this:

  • cy.visit("/")
  • cy.visit("/about")
  • cy.visit("/contact")