cypress 10.3.0 → 10.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/angular/CHANGELOG.md +55 -0
  2. package/angular/README.md +154 -0
  3. package/angular/dist/index.d.ts +1 -0
  4. package/angular/dist/index.js +263 -0
  5. package/angular/dist/mount.d.ts +111 -0
  6. package/angular/package.json +70 -0
  7. package/lib/exec/open.js +7 -2
  8. package/lib/exec/spawn.js +7 -2
  9. package/mount-utils/CHANGELOG.md +7 -1
  10. package/mount-utils/README.md +7 -0
  11. package/mount-utils/dist/index.js +8 -1
  12. package/mount-utils/package.json +1 -0
  13. package/package.json +26 -10
  14. package/react/CHANGELOG.md +13 -19
  15. package/react/README.md +28 -323
  16. package/react/dist/createMount.d.ts +28 -0
  17. package/react/dist/cypress-react.cjs.js +643 -99
  18. package/react/dist/cypress-react.esm-bundler.js +640 -100
  19. package/react/dist/getDisplayName.d.ts +1 -1
  20. package/react/dist/index.d.ts +2 -0
  21. package/react/dist/mount.d.ts +5 -141
  22. package/react/dist/types.d.ts +44 -0
  23. package/react/package.json +3 -5
  24. package/react18/CHANGELOG.md +6 -0
  25. package/react18/dist/cypress-react.cjs.js +633 -0
  26. package/react18/dist/cypress-react.esm-bundler.js +605 -0
  27. package/react18/dist/index.d.ts +5 -0
  28. package/react18/package.json +59 -0
  29. package/types/cypress.d.ts +24 -3
  30. package/types/index.d.ts +1 -1
  31. package/types/{net-stubbing.ts → net-stubbing.d.ts} +0 -0
  32. package/vue/CHANGELOG.md +16 -17
  33. package/vue/README.md +17 -607
  34. package/vue/dist/@vue/test-utils/baseWrapper.d.ts +63 -0
  35. package/vue/dist/@vue/test-utils/components/RouterLinkStub.d.ts +21 -0
  36. package/vue/dist/@vue/test-utils/config.d.ts +30 -0
  37. package/vue/dist/@vue/test-utils/constants/dom-events.d.ts +900 -0
  38. package/vue/dist/@vue/test-utils/createDomEvent.d.ts +9 -0
  39. package/vue/dist/@vue/test-utils/domWrapper.d.ts +18 -0
  40. package/vue/dist/@vue/test-utils/emit.d.ts +5 -0
  41. package/vue/dist/@vue/test-utils/errorWrapper.d.ts +1 -0
  42. package/vue/dist/@vue/test-utils/index.d.ts +11 -0
  43. package/vue/dist/@vue/test-utils/interfaces/wrapperLike.d.ts +56 -0
  44. package/vue/dist/@vue/test-utils/mount.d.ts +35 -0
  45. package/vue/dist/@vue/test-utils/stubs.d.ts +22 -0
  46. package/vue/dist/@vue/test-utils/types.d.ts +125 -0
  47. package/vue/dist/@vue/test-utils/utils/autoUnmount.d.ts +5 -0
  48. package/vue/dist/@vue/test-utils/utils/compileSlots.d.ts +2 -0
  49. package/vue/dist/@vue/test-utils/utils/componentName.d.ts +4 -0
  50. package/vue/dist/@vue/test-utils/utils/find.d.ts +10 -0
  51. package/vue/dist/@vue/test-utils/utils/flushPromises.d.ts +1 -0
  52. package/vue/dist/@vue/test-utils/utils/getRootNodes.d.ts +2 -0
  53. package/vue/dist/@vue/test-utils/utils/isElement.d.ts +1 -0
  54. package/vue/dist/@vue/test-utils/utils/isElementVisible.d.ts +6 -0
  55. package/vue/dist/@vue/test-utils/utils/matchName.d.ts +1 -0
  56. package/vue/dist/@vue/test-utils/utils/stringifyNode.d.ts +1 -0
  57. package/vue/dist/@vue/test-utils/utils/vueCompatSupport.d.ts +8 -0
  58. package/vue/dist/@vue/test-utils/utils/vueShared.d.ts +3 -0
  59. package/vue/dist/@vue/test-utils/utils.d.ts +13 -0
  60. package/vue/dist/@vue/test-utils/vueWrapper.d.ts +35 -0
  61. package/vue/dist/@vue/test-utils/wrapperFactory.d.ts +14 -0
  62. package/vue/dist/cypress-vue.cjs.js +5585 -5211
  63. package/vue/dist/cypress-vue.esm-bundler.js +5586 -5213
  64. package/vue/dist/index.d.ts +35 -3
  65. package/vue/package.json +11 -8
  66. package/vue2/CHANGELOG.md +7 -0
  67. package/vue2/README.md +11 -627
  68. package/vue2/dist/cypress-vue2.browser.js +267 -261
  69. package/vue2/dist/cypress-vue2.cjs.js +266 -260
  70. package/vue2/dist/cypress-vue2.esm-bundler.js +264 -258
  71. package/vue2/package.json +1 -1
  72. package/react/dist/cypress-react.browser.js +0 -497
package/react/README.md CHANGED
@@ -1,99 +1,32 @@
1
- > A little helper to unit test React components in the open source [Cypress.io](https://www.cypress.io/) test runner **v7.0.0+**
2
-
3
- **Jump to:** [Comparison](#comparison), [Blog posts](#blog-posts), [Install](#install), Examples: [basic](#basic-examples), [advanced](#advanced-examples), [full](#full-examples), [external](#external-examples), [Style options](#options), [Code coverage](#code-coverage), [Visual testing](#visual-testing), [Common problems](#common-problems), [Chat](#chat)
4
-
5
- ## TLDR
6
-
7
- - What is this? This package allows you to use [Cypress](https://www.cypress.io/) test runner to unit test your React components with zero effort. Here is a typical component testing, notice there is not external URL shown, since it is mounting the component directly.
8
-
9
- ![Example component test](images/dynamic.gif)
10
-
11
- - How is this different from [Enzyme](https://github.com/airbnb/enzyme) or [RTL](https://testing-library.com/docs/react-testing-library/intro)? It is similar in functionality BUT runs the component in the real browser with full power of Cypress E2E test runner: [live GUI, full API, screen recording, CI support, cross-platform](https://www.cypress.io/features/), and [visual testing](https://on.cypress.io/visual-testing).
12
- - If you like using `@testing-library/react`, you can use `@testing-library/cypress` for the same `findBy`, `queryBy` commands, see one of the examples in the list below
13
- - Read [My Vision for Component Tests in Cypress](https://glebbahmutov.com/blog/my-vision-for-component-tests/) by Gleb Bahmutov
14
-
15
- ## Comparison
16
-
17
- <!-- prettier-ignore-start -->
18
- Feature | Jest / Enzyme / RTL | Cypress + `@cypress/react`
19
- --- | --- | ---
20
- Test runs in real browser | ❌ | ✅
21
- Supports shallow mount | ✅ | ❌
22
- Supports full mount | ✅ | ✅
23
- Test speed | 🏎 | [as fast as the app works in the browser](#fast-enough)
24
- Test can use additional plugins | maybe | use any [Cypress plugin](https://on.cypress.io/plugins)
25
- Test can interact with component | synthetic limited API | use any [Cypress command](https://on.cypress.io/api)
26
- Test can be debugged | via terminal and Node debugger | use browser DevTools
27
- Built-in time traveling debugger | ❌ | Cypress time traveling debugger
28
- Re-run tests on file or test change | ✅ | ✅
29
- Test output on CI | terminal | terminal, screenshots, videos
30
- Tests can be run in parallel | ✅ | ✅ via [parallelization](https://on.cypress.io/parallelization)
31
- Test against interface | if using `@testing-library/react` | ✅ and can use `@testing-library/cypress`
32
- Spying and stubbing methods | Jest mocks | [Sinon library](https://on.cypress.io/stubs-spies-and-clocks)
33
- Stubbing imports | ✅ | ✅
34
- Stubbing clock | ✅ | ✅
35
- Code coverage | ✅ | ✅
36
- <!-- prettier-ignore-end -->
37
-
38
- If you are coming from Jest + RTL world, read [Test The Interface Not The Implementation](https://glebbahmutov.com/blog/test-the-interface/).
39
-
40
- If you are coming from Enzyme world, check out the [enzyme](cypress/component/basic/enzyme) example.
41
-
42
- ## Blog posts
43
-
44
- - [My Vision for Component Tests in Cypress](https://glebbahmutov.com/blog/my-vision-for-component-tests/)
45
- - [Unit Testing React components with Cypress](https://itnext.io/unit-testing-react-components-with-cypress-4d4cf8cd59a0)
46
- - [Test React Component with @cypress/react Example](https://dev.to/bahmutov/test-react-component-with-cypress-react-unit-test-example-4d99)
47
- - [Tic-Tac-Toe Component Tests](https://glebbahmutov.com/blog/tic-tac-toe-component-tests/)
48
- - [Using .env and .env.test from React component tests](https://medium.com/@bahmutov/using-env-and-env-test-from-react-component-tests-c11aa2040bc8)
49
- - [Visual testing for React components using open source tools](https://glebbahmutov.com/blog/open-source-visual-testing-of-components/)
50
- - [12 Recipes for testing React applications using @cypress/react](https://dev.to/bahmutov/12-recipes-for-testing-react-applications-using-cypress-react-unit-test-46g6) (compare to [12 Recipes for testing React applications using Testing Library](https://dev.to/jooforja/12-recipes-for-testing-react-applications-using-testing-library-1bh2#portal))
51
- - [Cypress Unit Testing React Components With TypeScript](https://medium.com/swlh/cypress-unit-testing-react-components-with-typescript-77b38e5043b3)
52
- - [Test The Interface Not The Implementation](https://glebbahmutov.com/blog/test-the-interface/) compares Jest + React Testing Library to @cypress/react + Cypress Testing Library
53
- - [Components People Test](https://glebbahmutov.com/blog/components-people-test/) about testing a component inside a Next.js-powered blog
1
+ # @cypress/react
54
2
 
55
- ## Install
56
-
57
- Requires [Node](https://nodejs.org/en/) version 12 or above.
3
+ Mount React components in the open source [Cypress.io](https://www.cypress.io/) test runner **v7.0.0+**
58
4
 
59
- ```sh
60
- npm install --save-dev cypress @cypress/react @cypress/webpack-dev-server
61
- ```
5
+ > **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [React Component Testing Docs](https://docs.cypress.io/guides/component-testing/quickstart-react#Configuring-Component-Testing) for mounting React components. Installing and importing `mount` from `@cypress/react` should only be used for advanced use-cases.
62
6
 
63
- ## Init
7
+ ## Install
64
8
 
65
- You can use our command line wizard to give you instructions on configuring this plugin. It will try to determine which framework or bundling tool you are using and give you instructions on right configuration.
9
+ - Requires Cypress v7.0.0 or later
10
+ - Requires [Node](https://nodejs.org/en/) version 12 or above
66
11
 
67
12
  ```sh
68
- npx create-cypress-tests --component-tests
13
+ npm install --save-dev @cypress/react
69
14
  ```
70
15
 
71
- Or continue with manual installation in the plugin file
72
-
73
- 1. Tell Cypress how your React application is transpiled or bundled (using Webpack), so Cypress can load your components. For example, if you use `react-scripts` (even after ejecting) do:
16
+ ## Run
74
17
 
75
- ```js
76
- // cypress/plugins/index.js
77
- module.exports = (on, config) => {
78
- require('@cypress/react/plugins/react-scripts')(on, config)
79
- // IMPORTANT to return the config object
80
- // with the any changed environment variables
81
- return config
82
- }
18
+ Open cypress test runner
19
+ ```
20
+ npx cypress open --component
83
21
  ```
84
22
 
85
- See [Recipes](./docs/recipes.md) for more examples.
86
-
87
- 2. You can specify a glob to locate component spec files. For example, to have them located in `src` folder use:
88
-
89
- ```json
90
- {
91
- "component": {
92
- "specPattern": "src/**/*.cy.jsx"
93
- }
94
- }
23
+ If you need to run test in CI
24
+ ```
25
+ npx cypress run --component
95
26
  ```
96
27
 
28
+ For more information, please check the official docs for [running Cypress](https://on.cypress.io/guides/getting-started/opening-the-app#Quick-Configuration) and for [component testing](https://on.cypress.io/guides/component-testing/writing-your-first-component-test).
29
+
97
30
  ## API
98
31
 
99
32
  - `mount` is the most important function, allows to mount a given React component as a mini web application and interact with it using Cypress commands
@@ -118,136 +51,6 @@ describe('HelloWorld component', () => {
118
51
 
119
52
  Look at the examples in [cypress/component](cypress/component) folder. Here is the list of examples showing various testing scenarios.
120
53
 
121
- ### Basic examples
122
-
123
- <!-- prettier-ignore-start -->
124
- Spec | Description
125
- --- | ---
126
- [alias](cypress/component/basic/alias) | Retrieve mounted component by its name or alias
127
- [alert-spec.js](cypress/component/basic/alert-spec.js) | Component tries to use `window.alert`
128
- [before-hook](cypress/component/basic/before-hook) | Mount the component from `before` hook to run multiple tests against it
129
- [counter-set-state](cypress/component/basic/counter-set-state) | Counter component that uses `this.state`
130
- [counter-use-hooks](cypress/component/basic/counter-use-hooks) | Counter component that uses `useState` hook
131
- [document-spec](cypress/component/basic/document) | Checks `document` dimensions from the component
132
- [enzyme](cypress/component/basic/enzyme) | Several specs showing how to recreate Enzyme's `setProps`, `setState`, and `setContext` methods.
133
- [emotion-spec.js](cypress/component/basic/emotion-spec.js) | Confirms the component is using `@emotion/core` and styles are set
134
- [error-boundary-spec.js](cypress/component/basic/error-boundary-spec.js) | Checks if an error boundary component works
135
- [fails-correctly](cypress/component/basic/fails-correctly) | Cypress test fails correctly when interacting with disabled elements
136
- [pure-component-spec.js](cypress/component/basic/pure-component.spec.js) | Tests stateless component
137
- [stateless-spec.js](cypress/component/basic/stateless-spec.js) | Passes Cypress stub to the component, confirms the component calls it on click
138
- [window-spec.js](cypress/component/basic/window-spec.js) | In the component test, the spec `window` and the application's `window` where the component is running should be the same object
139
- [css](cypress/component/basic/css) | Shows that component with `import './Button.css'` works
140
- [css modules](cypress/component/basic/css-modules) | Shows that component that using css modules styles works
141
- [network](cypress/component/basic/network) | Confirms we can use `cy.route` to stub / spy on component's network calls
142
- [no-visit](cypress/component/basic/no-visit) | Component specs cannot call `cy.visit`
143
- [rerender](cypress/component/basic/rerender) | Checking how the component re-renders when its props change
144
- [react-book-by-chris-noring](cypress/component/basic/react-book-by-chris-noring) | Copied test examples from [React Book](https://softchris.github.io/books/react) and adapted for Cypress component tests
145
- [react-tutorial](cypress/component/basic/react-tutorial) | Tests from official [ReactJS tutorial](https://reactjs.org/tutorial/tutorial.html) copied and adapted for Cypress component tests
146
- [stub-example](cypress/component/basic/stub-example) | Uses `cy.stub` as component props
147
- [styles](cypress/component/basic/styles) | Add extra styles to the component during testing using `style`, `cssFile` or `stylesheets` mount options
148
- [toggle-example](cypress/component/basic/toggle-example) | Testing a toggle component using Cypress DOM commands
149
- [typescript](cypress/component/basic/typescript) | A spec written in TypeScript
150
- [unmount](cypress/component/basic/unmount) | Verifies the component's behavior when it is unmounted from the DOM
151
- [use-lodash-fp](cypress/component/basic/use-lodash-fp) | Imports and tests methods from `lodash/fp` dependency
152
- [styled-components](cypress/component/basic/styled-components) | Test components that use [styled-components](https://www.styled-components.com/)
153
- <!-- prettier-ignore-end -->
154
-
155
- plus a few smaller sanity specs in [cypress/component/basic](cypress/component/basic) folder.
156
-
157
- ### Advanced examples
158
-
159
- <!-- prettier-ignore-start -->
160
- Spec | Description
161
- --- | ---
162
- [api-test](cypress/component/advanced/api-test) | Mix [REST api tests](https://glebbahmutov.com/blog/api-testing-with-sever-logs/) that use [cy-api](https://github.com/bahmutov/cy-api) with component tests
163
- [app-action-example](cypress/component/advanced/app-action-example) | App actions against components
164
- [context](cypress/component/advanced/context) | Confirms components that use React context feature work
165
- [custom-command](cypress/component/advanced/custom-command) | Wraps `mount` in a custom command for convenience
166
- [forward-ref](cypress/component/advanced/forward-ref) | Tests a component that uses a forward ref feature
167
- [hooks](cypress/component/advanced/hooks) | Tests several components that use React Hooks like `useState`, `useCallback`
168
- [lazy-loaded](cypress/component/advanced/lazy-loaded) | Confirms components that use `React.lazy` and dynamic imports work
169
- [material-ui-example](cypress/component/advanced/material-ui-example) | Large components demos from [Material UI](https://material-ui.com/)
170
- [mobx-v6](cypress/component/advanced/mobx-v6) | Test components with MobX v6 observable
171
- [mock-fetch](cypress/component/advanced/mock-fetch) | Test stubs `window.fetch` used by component in `useEffect` hook
172
- [mocking-axios](cypress/component/advanced/mocking-axios) | Stubbing methods from a 3rd party component like `axios`
173
- [mocking-component](cypress/component/advanced/mocking-component) | Replaced a child component with dummy component during test
174
- [mocking-imports](cypress/component/advanced/mocking-imports) | Stub a named ES6 import in various situations
175
- [react-router-v6](cypress/component/advanced/react-router-v6) | Example testing a [React Router v6](https://github.com/ReactTraining/react-router). Both browser and in memory routers
176
- [renderless](cypress/component/advanced/renderless) | Testing a component that does not need to render itself into the DOM
177
- [set-timeout-example](cypress/component/advanced/set-timeout-example) | Control the clock with `cy.tick` and test loading components that use `setTimeout`
178
- [test-retries](cypress/component/advanced/test-retries) | This component is compatible with [Cypress Test Retries](https://github.com/cypress-io/cypress/pull/3968)
179
- [testing-lib-example](cypress/component/advanced/testing-lib-example) | A spec adopted from [@testing-library/react](https://testing-library.com/docs/react-testing-library/example-intro) that uses [@testing-library/cypress](https://testing-library.com/docs/cypress-testing-library/intro)
180
- [timers](cypress/component/advanced/timers) | Testing components that set timers, adopted from [ReactJS Testing recipes](https://reactjs.org/docs/testing-recipes.html#timers)
181
- [tutorial](cypress/component/advanced/tutorial) | A few tests adopted from [ReactJS Tutorial](https://reactjs.org/tutorial/tutorial.html), including Tic-Tac-Toe game
182
- [use-local-storage](cypress/component/advanced/use-local-storage) | Use hooks to load and save items into `localStorage`
183
- [portal](cypress/component/advanced/portal) | Component test for `ReactDOM.createPortal` feature
184
- [radioactive-state](cypress/component/advanced/radioactive-state) | Testing components that use [radioactive-state](https://github.com/MananTank/radioactive-state) library
185
- [react-bootstrap](cypress/component/advanced/react-bootstrap) | Confirms [react-bootstrap](https://react-bootstrap.github.io/) components are working
186
- [select React component](cypress/component/advanced/react-book-example/src/components/ProductsList.spec.js) | Uses [cypress-react-selector](https://github.com/abhinaba-ghosh/cypress-react-selector) to find DOM elements using React component name and state values
187
- [lazy-loaded](cypress/component/advanced/lazy-loaded-suspense) | Uses multiple chunks and async components with `React.lazy` + `React.Suspense`.
188
- [i18n](cypress/component/advanced/i18n) | Uses[react-i18next](https://react.i18next.com/) for localizaiton.
189
- [framer-motion](cypress/component/advanced/framer-motion) | Uses [framer motion](https://www.framer.com/motion/) for javascript-based animation.
190
- <!-- prettier-ignore-end -->
191
-
192
- ### Full examples
193
-
194
- We have several subfolders in [examples](examples) folder that have complete projects with just their dependencies installed in the root folder.
195
-
196
- <!-- prettier-ignore-start -->
197
- Folder Name | Description
198
- --- | ---
199
- [a11y](examples/a11y) | Testing components' accessibility using [cypress-axe](https://github.com/avanslaars/cypress-axe)
200
- [react-scripts](examples/react-scripts) | A project using `react-scripts` with component tests in `src` folder, including the `.env` files demo.
201
- [react-scripts-folder](examples/react-scripts-folder) | A project using `react-scripts` with component tests in `cypress/component`
202
- [tailwind](examples/tailwind) | Testing styles built using [Tailwind CSS](https://tailwindcss.com/)
203
- [sass-and-ts](examples/sass-and-ts) | Example with Webpack, Sass and TypeScript
204
- [snapshots](examples/snapshots) | Component HTML and JSON snapshots using [cypress-plugin-snapshots](https://github.com/meinaart/cypress-plugin-snapshots)
205
- [visual-sudoku](examples/visual-sudoku) | [Visual testing](#visual-testing) for components using open source plugin [cypress-image-snapshot](https://github.com/palmerhq/cypress-image-snapshot). For larger example with an hour long list of explanation videos, see [bahmutov/sudoku](https://github.com/bahmutov/sudoku).
206
- [visual-testing-with-percy](examples/visual-testing-with-percy) | [Visual testing](#visual-testing) for components using 3rd party service [Percy.io](https://percy.io/)
207
- [visual-testing-with-happo](examples/visual-testing-with-happo) | [Visual testing](#visual-testing) for components using 3rd party service [Happo](https://happo.io/)
208
- [visual-testing-with-applitools](examples/visual-testing-with-applitools) | [Visual testing](#visual-testing) for components using 3rd party service [Applitools.com](https://applitools.com/)
209
- [using-babel](examples/using-babel) | Bundling specs and loaded source files using project's existing `.babelrc` file
210
- [webpack-file](examples/rollup) | Bundle component and specs using [rollup](http://rollupjs.org/guide/en/).
211
- [webpack-file](examples/webpack-file) | Load existing `webpack.config.js` file
212
- [webpack-options](examples/webpack-options) | Using the default Webpack options from `@cypress/webpack-preprocessor` to transpile JSX specs
213
- <!-- prettier-ignore-end -->
214
-
215
- ### External examples
216
-
217
- This way of component testing has been verified in a number of forked 3rd party projects.
218
-
219
- <!-- prettier-ignore-start -->
220
- Repo | Description
221
- --- | ---
222
- [try-cra-with-unit-test](https://github.com/bahmutov/try-cra-with-unit-test) | Hello world initialized with CRAv3
223
- [try-cra-app-typescript](https://github.com/bahmutov/try-cra-app-typescript) | Hello world initialized with CRAv3 `--typescript`
224
- [react-todo-with-hooks](https://github.com/bahmutov/react-todo-with-hooks) | Modern web application using hooks
225
- [test-redux-examples](https://github.com/bahmutov/test-redux-examples) | Example apps copies from official Redux repo and tested as components
226
- [test-react-hooks-animations](https://github.com/bahmutov/test-react-hooks-animations) | Testing React springs fun blob animation
227
- [test-mdx-example](https://github.com/bahmutov/test-mdx-example) | Example testing MDX components using Cypress
228
- [test-apollo](https://github.com/bahmutov/test-apollo) | Component testing an application that uses Apollo GraphQL library
229
- [test-xstate-react](https://github.com/bahmutov/test-xstate-react) | XState component testing using Cypress
230
- [test-react-router-v5](https://github.com/bahmutov/test-react-router-v5) | A few tests of React Router v5
231
- [test-material-ui](https://github.com/bahmutov/test-material-ui) | Testing Material UI components: date pickers, lists, autocomplete
232
- [test-d3-react-gauge](https://github.com/bahmutov/test-d3-react-gauge) | Testing React D3 gauges
233
- [storybook-code-coverage](https://github.com/bahmutov/storybook-code-coverage) | Example app where we get 100% code coverage easily with a single integration spec and a few component specs, replacing [several tools](https://dev.to/penx/combining-storybook-cypress-and-jest-code-coverage-4pa5)
234
- [react-loading-skeleton](https://github.com/bahmutov/react-loading-skeleton) | One to one Storybook tests for React skeleton components. Uses local `.babelrc` settings without Webpack config
235
- [test-swr](https://github.com/bahmutov/test-swr) | Component test for [Zeit SWR](https://github.com/zeit/swr) hooks for remote data fetching
236
- [emoji-search](https://github.com/bahmutov/emoji-search) | Quick component test for a fork of emoji-search
237
- [test-custom-error-boundary](https://github.com/bahmutov/test-custom-error-boundary) | Play with a component that implements error boundary
238
- [Jscrambler-Webpack-React](https://github.com/bahmutov/Jscrambler-Webpack-React) | Example project with its own Webpack config file
239
- [bahmutov/integration-tests](https://github.com/bahmutov/integration-tests) | Example based on blog post [React Integration Testing: Greater Coverage, Fewer Tests](https://css-tricks.com/react-integration-testing-greater-coverage-fewer-tests/)
240
- [mobx-react-typescript-boilerplate](https://github.com/bahmutov/mobx-react-typescript-boilerplate) | Fork of the official Mobx example, shows clock control
241
- [bahmutov/test-react-hook-form](https://github.com/bahmutov/test-react-hook-form) | Testing forms created using [react-hook-form](https://github.com/react-hook-form/react-hook-form)
242
- [bahmutov/testing-react-example](https://github.com/bahmutov/testing-react-example) | Described in blog post [Test React Component with @cypress/react Example](https://dev.to/bahmutov/test-react-component-with-@cypress/react-example-4d99)
243
- [ejected-react-scripts-example](https://github.com/bahmutov/ejected-react-scripts-example) | Using component testing after ejecting `react-scripts`
244
- [tic-tac-toe](https://github.com/bahmutov/react-tic-tac-toe-example) | Component and unit tests for Tic-Tac-Toe, read [Tic-Tac-Toe Component Tests](https://glebbahmutov.com/blog/tic-tac-toe-component-tests/)
245
- [react-hooks-file-upload](https://github.com/bahmutov/react-hooks-file-upload) | Upload a file from the component while stubbing the server
246
- [react-query-example](https://github.com/bahmutov/react-query-example) | Quick test example for components that use `react-query` with mock clock control
247
- <!-- prettier-ignore-end -->
248
-
249
- To find more examples, see GitHub topic [@cypress/react-example](https://github.com/topics/@cypress/react-example)
250
-
251
54
  ## Options
252
55
 
253
56
  In most cases, the component already imports its own styles, thus it looks "right" during the test. If you need another CSS, the simplest way is to import it from the spec file:
@@ -278,23 +81,6 @@ mount(<Todo todo={todo} />, {
278
81
  })
279
82
  ```
280
83
 
281
- <details>
282
- <summary>Additional configuration</summary>
283
- If your React and React DOM libraries are installed in non-standard paths (think monorepo scenario), you can tell this plugin where to find them. In `cypress.json` specify paths like this:
284
-
285
- ```json
286
- {
287
- "env": {
288
- "@cypress/react": {
289
- "react": "node_modules/react/umd/react.development.js",
290
- "react-dom": "node_modules/react-dom/umd/react-dom.development.js"
291
- }
292
- }
293
- }
294
- ```
295
-
296
- </details>
297
-
298
84
  You may also specify the `ReactDOM` package to use. This can be useful in complex monorepo setups that have different versions of React and React DOM installed. If you see an error relating to [mismatching versions of React or React DOM](https://reactjs.org/warnings/invalid-hook-call-warning.html#mismatching-versions-of-react-and-react-dom), this may be the solution. You can do this using the `ReactDom` option:
299
85
 
300
86
  ```jsx
@@ -309,106 +95,25 @@ mount(<Todo todo={todo} />, {
309
95
  })
310
96
  ```
311
97
 
312
- ## Code coverage
313
-
314
- In order to use code coverage you can follow the instructions from [docs](https://github.com/cypress-io/code-coverage). In most of cases you need to install 2 dependencies:
315
-
316
- ```
317
- npm i @cypress/code-coverage babel-plugin-istanbul
318
-
319
- yarn add @cypress/code-coverage babel-plugin-istanbul
320
- ```
321
-
322
- If you are using [plugins/cra-v3](plugins/cra-v3) it instruments the code on the fly using `babel-plugin-istanbul` and generates report using dependency [cypress-io/code-coverage](https://github.com/cypress-io/code-coverage) (included). If you want to disable code coverage instrumentation and reporting, use `--env coverage=false` or `CYPRESS_coverage=false` or set in your `cypress.json` file
323
-
324
- ```json
325
- {
326
- "env": {
327
- "coverage": false
328
- }
329
- }
330
- ```
331
-
332
- ## Visual testing
333
-
334
- You can use any Cypress [Visual Testing plugin](https://on.cypress.io/plugins#visual-testing) to perform [visual testing](https://on.cypress.io/visual-testing) from the component tests. This repo has several example projects, see [visual-sudoku](examples/visual-sudoku), [visual-testing-with-percy](examples/visual-testing-with-percy), [visual-testing-with-happo](examples/visual-testing-with-happo), and [visual-testing-with-applitools](examples/visual-testing-with-applitools).
335
-
336
- For a larger Do-It-Yourself example with an hour long list of explanation videos, see [bahmutov/sudoku](https://github.com/bahmutov/sudoku) repository. I explain how to write visual testing using open source tools in this [blog post](https://glebbahmutov.com/blog/open-source-visual-testing-of-components/), [video talk](https://www.youtube.com/watch?v=00BNExlJUU8), and [slides](https://slides.com/bahmutov/i-see-what-is-going-on).
337
-
338
- ## Common problems
339
-
340
- <details id="fast-enough">
341
- <summary>Slower than Jest</summary>
342
-
343
- When you use `cypress-X-unit-test` for component testing, you might notice the tests are slower than using Jest to test the same components. Yes, that's true. A test runner could be made _extremely_ fast if it did nothing, just check out the [auchenberg/volkswagen](https://github.com/auchenberg/volkswagen) test runner - it is blazing on CI 😉. Of course, Jest does do things, just not inside the real browser environment.
344
-
345
- Testing using Jest with its jsdom browser is faster than starting the real browser, loading all libraries, mounting the component and then waiting for the component to actually perform its work in response to the test's actions. But do those tests give you a true confidence that the component is working?
346
-
347
- Try this test 🙈
348
-
349
- Spoiler: it fails, [proof](https://codesandbox.io/s/react-testing-library-demo-forked-z7l2o?file=/src/__tests__/components.js).
350
-
351
- ```js
352
- const mock = jest.fn()
353
- // render a component that does NOT allow any click events
354
- // using pointerEvents: "none" style
355
- const { getByRole } = render(
356
- <button style={{ pointerEvents: 'none' }} onClick={mock}>
357
- text
358
- </button>,
359
- )
360
- // Jest happily clicks
361
- fireEvent.click(getByRole('button'))
362
- expect(mock).not.toBeCalled()
363
- ```
364
-
365
- Cypress test on the other hand [fails correctly](cypress/component/basic/fails-correctly).
366
-
367
- We think that using `cypress-X-unit-test` runs tests as _fast as your application code is_, and often you need to think how to _slow down_ the Cypress Test Runner so it does not run away from the component's code, just see our blog posts dealing with [test flake](https://cypress.io/blog/tag/flake/).
98
+ ## Compatibility
368
99
 
369
- From the developer's perspective I would ask myself: which tests do I _write faster_? What happens when a test fails and I need to debug the failure: which test runner allows me to _debug a failed test quicker_? While I am partial, I have to say, realistic Cypress tests are easier to write and debug.
370
-
371
- Finally, when running tests on the continuous integration service, the true test speed up comes from properly configuring [dependencies caching](https://on.cypress.io/caching) and running [tests in parallel](https://on.cypress.io/parallelization) - something we have extensively documented and consider a solved problem.
372
-
373
- </details>
374
-
375
- ## Context Provider usage
376
-
377
- React context provider usage and API described in [./docs/providers-and-composition.md](./docs/providers-and-composition.md)
378
-
379
- ## Chat
380
-
381
- Come chat with us [on discord](https://discord.gg/7ZHYhZSW) in the #component-testing channel.
100
+ | @cypress/react | cypress |
101
+ | -------------- | ------- |
102
+ | <= v5 | <= v9 |
103
+ | >= v6 | >= v10 |
382
104
 
383
105
  ## Development
384
106
 
385
- See [docs/development.md](./docs/development.md)
386
-
387
- ## Debugging
107
+ Run `yarn build` to compile and sync packages to the `cypress` cli package.
388
108
 
389
- You can see verbose logs from this plugin by running with environment variable
390
-
391
- ```
392
- DEBUG=@cypress/react
393
- ```
394
-
395
- Because finding and modifying Webpack settings while running this plugin is done by [find-webpack](https://github.com/bahmutov/find-webpack) module, you might want to enable its debug messages too.
396
-
397
- ```
398
- DEBUG=@cypress/react,find-webpack
399
- ```
109
+ Run `yarn cy:open` to open Cypress component testing against real-world examples.
400
110
 
401
- ## Changelog
111
+ Run `yarn test` to execute headless Cypress tests.
402
112
 
403
- [Changelog](./CHANGELOG.md)
113
+ ## License
404
114
 
405
- ## Related tools
115
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
406
116
 
407
- Same feature for unit testing components from other frameworks using Cypress
117
+ This project is licensed under the terms of the [MIT license](/LICENSE).
408
118
 
409
- - [@cypress/vue](https://github.com/cypress-io/cypress/tree/develop/npm/vue)
410
- - [cypress-cycle-unit-test](https://github.com/bahmutov/cypress-cycle-unit-test)
411
- - [cypress-svelte-unit-test](https://github.com/bahmutov/cypress-svelte-unit-test)
412
- - [@cypress/angular](https://github.com/bahmutov/@cypress/angular)
413
- - [cypress-hyperapp-unit-test](https://github.com/bahmutov/cypress-hyperapp-unit-test)
414
- - [cypress-angularjs-unit-test](https://github.com/bahmutov/cypress-angularjs-unit-test)
119
+ ## [Changelog](./CHANGELOG.md)
@@ -0,0 +1,28 @@
1
+ /// <reference types="cypress" />
2
+ import * as React from 'react';
3
+ import type { InternalMountOptions, MountOptions, MountReturn, UnmountArgs } from './types';
4
+ /**
5
+ * Create an `mount` function. Performs all the non-React-version specific
6
+ * behavior related to mounting. The React-version-specific code
7
+ * is injected. This helps us to maintain a consistent public API
8
+ * and handle breaking changes in React's rendering API.
9
+ *
10
+ * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
11
+ * or people writing adapters for third-party, custom adapters.
12
+ */
13
+ export declare const makeMountFn: (type: 'mount' | 'rerender', jsx: React.ReactNode, options?: MountOptions, rerenderKey?: string | undefined, internalMountOptions?: InternalMountOptions | undefined) => globalThis.Cypress.Chainable<MountReturn>;
14
+ /**
15
+ * Create an `unmount` function. Performs all the non-React-version specific
16
+ * behavior related to unmounting.
17
+ *
18
+ * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
19
+ * or people writing adapters for third-party, custom adapters.
20
+ */
21
+ export declare const makeUnmountFn: (options: UnmountArgs) => Cypress.Chainable<undefined>;
22
+ declare const _mount: (jsx: React.ReactNode, options?: MountOptions) => Cypress.Chainable<MountReturn>;
23
+ export declare const createMount: (defaultOptions: MountOptions) => (element: React.ReactElement, options?: Partial<import("@cypress/mount-utils").StyleOptions & import("./types").MountReactComponentOptions> | undefined) => Cypress.Chainable<MountReturn>;
24
+ /** @deprecated Should be removed in the next major version */
25
+ export default _mount;
26
+ export interface JSX extends Function {
27
+ displayName: string;
28
+ }