Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Using the built in cypress typescript support - component tests results in webpack error #178

@basarat

Description

@basarat

Example error:

Error: Webpack Compilation Error
./cypress/component/App.test.tsx 7:10
Module parse failed: Unexpected token (7:10)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| describe('HelloWorld component', () => {
|   it('works', () => {
>     mount(<App />);
|     // use standard Cypress commands
|     cy.contains('learn react').should('be.visible');
 @ multi ./cypress/component/App.test.tsx main[0]

Setup

  • Create project:
npx create-react-app my-app --template typescript
cd my-app
npm i cypress cypress-react-unit-test
  • cypress.json
{
  "experimentalComponentTesting": true
}
  • cypress/plugins/index.js
module.exports = (on, config) => {
  require('cypress-react-unit-test/plugins/react-scripts')(on, config)
  return config
}
  • cypress/component/App.test.tsx
import React from 'react';
import { mount } from 'cypress-react-unit-test'
import App from '../../src/App';

describe('HelloWorld component', () => {
  it('works', () => {
    mount(<App />);
    // use standard Cypress commands
    cy.contains('learn react').should('be.visible');
  });
});
  • Now run npx cypress open and select the component test App.test.tsx. You will see the error as shown:

image

The default zero config cypress support for TypeScript in integration tests is lovely and would like the same for component tests 🌹

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions