Files
cypress/npm/react/examples/webpack-options
Alejandro Estrada 8a6768fee6 feat: use devServer instad of startDevServer (#20092)
* feat: use devServer instad of startDevServer

* Fix tests

* Update with feedback

Co-authored-by: Zachary Williams <ZachJW34@gmail.com>
2022-02-11 09:46:58 -05:00
..

example: webpack-options

The Webpack devServer in cypress/plugins/index.js adds the Babel React preset to the list of default Webpack plugins. This allows Cypress to transpile JSX code in cypress/component/Test.cy-spec.js file.

Usage

  1. Make sure the root project has been built .
# in the root of the project
npm install
npm run build
  1. Run npm install in this folder to symlink the @cypress/react dependency.
# in this folder
npm install
  1. Start Cypress
npm run cy:open
# or just run headless tests
npm test

Example

import React from 'react'
import { mount } from '@cypress/react'
describe('components', () => {
  it('works', () => {
    mount(<div>Text</div>)
    cy.contains('Text')
  })
})

Test screenshot

More tests are in the cypress/component folder.