This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
cypress/component/advanced Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ Spec | Description
128128--- | ---
129129[ app-action-example] ( cypress/component/advanced/app-action-example ) | App actions against components
130130[ context] ( cypress/component/advanced/context ) | Confirms components that use React context feature work
131+ [ custom-command] ( cypress/component/custom-command ) | Wraps ` mount ` in a custom command for convenience
131132[ forward-ref] ( cypress/component/advanced/forward-ref ) | Tests a component that uses a forward ref feature
132133[ hooks] ( cypress/component/advanced/hooks ) | Tests several components that use React Hooks like ` useState ` , ` useCallback `
133134[ lazy-loaded] ( cypress/component/advanced/lazy-loaded ) | Confirms components that use ` React.lazy ` and dynamic imports work
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ /// <reference types="../../lib" />
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-test'
5+
6+ // https://github.com/bahmutov/cypress-react-unit-test/issues/184
7+ Cypress . Commands . add ( 'myMount' , ( ) => {
8+ return mount ( < div > My mount</ div > )
9+ } )
10+
11+ Cypress . Commands . add ( 'myMount2' , ( ) => {
12+ const toMount = React . createElement ( 'div' , null , [ 'mount 2' ] )
13+ return mount ( toMount )
14+ } )
15+
16+ describe ( 'Wrapped mount in custom command' , ( ) => {
17+ it ( 'works' , ( ) => {
18+ cy . myMount ( )
19+ cy . contains ( 'My mount' )
20+ } )
21+
22+ it ( 'works using React.createElement' , ( ) => {
23+ cy . myMount2 ( )
24+ cy . contains ( 'mount 2' )
25+ } )
26+ } )
Original file line number Diff line number Diff line change 22/// <reference types="../../lib" />
33
44import React from 'react'
5- import ReactDom from 'react-dom'
65import { mount } from 'cypress-react-unit-test'
76import Button from './forward-ref.jsx'
87
You can’t perform that action at this time.
0 commit comments