Skip to main content
Cypress App

React API

Methods​

mount​

import { mount } from 'cypress/react'
DescriptionMounts a React component into the DOM.
Signature

mount(jsx: React.ReactNode, options?: MountOptions, rerenderKey?: string): Cypress.Chainable<MountReturn>

ReturnsCypress.Chainable<MountReturn>
mount Parameters
NameTypeDescription
jsxReact.JSX.ElementThe React component to mount.
optionsMountOptions (optional)The options for mounting the component
rerenderKeystring (optional)A key to use to force a rerender.

Example​

import { mount } from '@cypress/react'
import { Stepper } from './Stepper'

it('mounts', () => {
mount(<StepperComponent />)
cy.get('[data-cy=increment]').click()
cy.get('[data-cy=counter]').should('have.text', '1')
}

getContainerEl​

DescriptionGets the root element used to mount the component.
Signature() => HTMLElement
ReturnsHTMLElement

Interfaces​

MountOptions​

members
NameTypeDescription
aliasstring (optional)
ReactDomMountReactComponentOptions.ReactDom (optional)
logboolean (optional)Log the mounting command into Cypress Command Log, true by default
strictboolean (optional)

Render component in React strict mode It activates additional checks and warnings for child components.

MountReturn​

Type that the mount function yields

members
NameTypeDescription
componentReact.ReactNode

Render component in React strict mode It activates additional checks and warnings for child components.

rerender

(component: React.ReactNode) => globalThis.Cypress.Chainable<MountReturn>

The component that was rendered.