You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 5, 2022. It is now read-only.
If you need help configuring bundler, see [preprocessors info](https://gitpitch.com/cypress-io/testing-workshop-cypress?p=slides/16-preprocessors)
26
-
27
21
## Use
28
22
29
-
Include this plugin from `cypress/support/index.js`
23
+
Include this plugin from your project's `cypress/support/index.js`
30
24
31
25
```js
32
-
import'cypress-react-unit-test'
26
+
require('cypress-react-unit-test/dist/hooks')
33
27
```
34
28
35
-
This adds a new command `cy.mount` that can mount a React component. It also overloads `cy.get` to accept in addition to selectors React component, returning it. See examples below.
29
+
Then turn the experimental component support on in your `cypress.json`. You can also specify where component spec files are located. For exampled to have them located in `src` folder use:
30
+
31
+
```json
32
+
{
33
+
"experimentalComponentTesting": true,
34
+
"componentFolder": "src"
35
+
}
36
+
```
36
37
37
38
## Example
38
39
39
40
```js
40
-
// load Cypress TypeScript definitions for IntelliSense
41
-
/// <reference types="cypress" />
42
-
// import the component you want to test
43
-
import { HelloState } from'../../src/hello-x.jsx'
44
41
importReactfrom'react'
45
-
describe('HelloState component', () => {
42
+
import { mount } from'cypress-react-unit-test'
43
+
import { HelloWorld } from'./hello-world.jsx'
44
+
describe('HelloWorld component', () => {
46
45
it('works', () => {
47
-
// mount the component under test
48
-
cy.mount(<HelloState />)
49
-
// start testing!
50
-
cy.contains('Hello Spider-man!')
51
-
// mounted component can be selected via its name, function, or JSX
52
-
// e.g. '@HelloState', HelloState, or <HelloState />
0 commit comments