Created
May 7, 2020 05:59
-
-
Save basarat/df1f7a689139b6404deea49ed86bf95f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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": [ | |
"cypress" | |
] | |
// package.json | |
Scripts | |
"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 | |
require('cypress-react-unit-test/support') | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick note cypress-react-unit-test has been renamed to @cypress/react.