Skip to content

Instantly share code, notes, and snippets.

Created May 7, 2020 05:59
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// create react app
npx create-react-app my-app --template typescript
cd my-react-app
// install
npm i cypress cypress-react-unit-test
// tsconfig.json
"types": [
// package.json
"cypress:open": "cypress open",
"cypress:run": "cypress run"
// cypress.json
"experimentalComponentTesting": true,
"componentFolder": "src/cypress/component",
"integrationFolder": "src/cypress/integration",
"supportFile": "src/cypress/support/index.js",
"pluginsFile": "src/cypress/plugins/index.js",
"fixturesFolder": false
// src/cypress/support/index.js
// src/cypress/plugins/index.js
module.exports = (on, config) => {
require('cypress-react-unit-test/plugins/react-scripts')(on, config)
return config
// src/cypress/component/App.test.tsx
import React from 'react';
import { mount } from 'cypress-react-unit-test’;
import App from '../../App';
describe('App', () => {
it('renders learn react link', () => {
mount(<App />);
// use standard Cypress commands
cy.contains('Learn React').should('be.visible');
// Run
npm run cypress:open
// See coverage
open coverage/lcov-report/index.html
// remove RTL (react testing library) from package.json
Copy link

nufaylr commented Mar 5, 2021

Quick note cypress-react-unit-test has been renamed to @cypress/react.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment