Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Cypress Component Test Types in React?

I'm trying to create a component test in cypress. I did the setup and all basics tests are working fine.

Now I tried to mock a function with jest:

import { mount } from '@cypress/react'

const onDissmis = jest.fn()

describe('Tags', () => {

  describe('Basic', () => {
    mount(<Component onDismiss={onDissmis} />)
  })
})

I also get the intellisense from VSCode: enter image description here

However when I try to run the code I get:

The following error originated from your test code, not from Cypress.

  > jest is not defined

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.

Probably the ts config is wrong (so it's just referencing me jest but it's not using jest) Maybe mocha? How can I configure the project that it's correct?

This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "types": [
      "cypress"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src",
    "craco.config.js",
    "**/*.ts"
  ]
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don;t know about using Jest with Cypress (you may just be able to add Jest package to the app).

But Cypress has cy.stub(). Does this work?

import { mount } from '@cypress/react'

const onDissmis = cy.stub()

describe('Tags', () => {

  describe('Basic', () => {
    mount(<Component onDismiss={onDissmis} />)
  })
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!