https://github.com/bahmutov/try-cra-app-typescript
An example of Create-React-App v3 using TypeScript with Cypress unit tests
https://github.com/bahmutov/try-cra-app-typescript
cypress-react-unit-test-example
Last synced: 4 months ago
JSON representation
An example of Create-React-App v3 using TypeScript with Cypress unit tests
- Host: GitHub
- URL: https://github.com/bahmutov/try-cra-app-typescript
- Owner: bahmutov
- Created: 2020-04-03T13:27:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-28T07:01:13.000Z (8 months ago)
- Last Synced: 2024-10-03T14:17:33.575Z (8 months ago)
- Topics: cypress-react-unit-test-example
- Language: TypeScript
- Size: 2.7 MB
- Stars: 6
- Watchers: 1
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# try-cra-app-typescript
[![ci status][ci image]][ci url]   This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app) using TypeScript template
```shell
$ npx create-react-app try-cra-app-typescript --template typescript
info Direct dependencies
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
```Then add Cypress and [cypress-react-unit-test](https://github.com/bahmutov/cypress-react-unit-test)
```shell
$ yarn add -D cypress cypress-react-unit-test
info Direct dependencies
├─ [email protected]
└─ [email protected]
```Create [cypress.json](cypress.json) and point at the unit testing settings: support and plugins to read the create-react-app webpack config and load tests from [src](src) folder.
Create [src/App.cy-spec.tsx](src/App.cy-spec.tsx). Run using `yarn cypress open` and you should see the working component test.

The test vs the original [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) test file (nothing like type clashes between Mocha and Jest assertions, right)

## Code coverage
The component tests collect code coverage automatically. You should see messages in the command log.

When running on CI, the collected coverage information is checked using [check-code-coverage](https://github.com/bahmutov/check-code-coverage) utility. If the code coverage is not being collected, run Cypress with environment variable to see logs:
```
DEBUG=cypress-react-unit-test,find-webpack
```[ci image]: https://github.com/bahmutov/try-cra-app-typescript/workflows/master/badge.svg?branch=master
[ci url]: https://github.com/bahmutov/try-cra-app-typescript/actions