Mount and Test a Vue 3 Component in Cypress

InstructorFilip Hric

Share this video with your friends

Send Tweet

To create our first test, you’ll create a spec file that pairs with the component. Usual naming convention is using filename.cy.ts (or .js), but this can be easily set up in cypres.config.ts file. After you create the spec file, you can mount the component by importing it and using cy.mount() command inside an it() block. This will render the component inside Cypress app, but will not load all the dependencies that the component needs, like css styles. These need to be imported into the spec file manually. Since we are running our component in a browser and inside a Cypress app, we can interact with it using common Cypress commands.