1

We have introduced cypress 9.3.1 in our project for e2e test. Now we face the problem that our existing jest test don't compile in the CI.

The following error occures for all parameterized tests:

Property 'each' does not exist on type 'TestFunction'.
       it.each<TestCase>([

Question: How to fix it?


What we tried and did't work:

  • Adding import { it } from '@jest/globals' to every test. We where able to fix a similar problem (Property 'toBeTruthy' does not exist on type 'Assertion') by adding import { expect } from '@jest/globals' to every test. See: https://stackoverflow.com/a/65153905

  • Adding a project wide exclusion for cypress globals, by adding "exclude": ["cypress/global.d.ts"] to the tsconfig.spec.json

Chriss
  • 5,157
  • 7
  • 41
  • 75
  • Just for others looking at this problem: Adding `import { it } from '@jest/globals'` did work for us. As we are additionally using jasmine in this project, the jasmine type definitions where loaded here by default. – CodeMonkey1770 May 25 '22 at 08:02

2 Answers2

3

Just ran into this problem as well, it turned out a conflicting type definition from mocha was included in our tsconfig.json. Make sure that you aren't loading Mocha's type definitions.

Edit: what we ended up needing to do was creating a separate tsconfig.json for our cypress tests, as described here: https://docs.cypress.io/guides/tooling/typescript-support#Configure-tsconfig-json

JRJurman
  • 1,615
  • 2
  • 19
  • 30
0

We are using the tsconfig.json as described here (see @JRJurman answer) but that doesn't worked in our project.

Now we are using the cypress-each plugin, developed by one of the cypress contributors.

npm i -D cypress-each

usage:

import 'cypress-each'

// create a separate test for each selector
const selectors = ['header', 'footer', '.new-todo']
it.each(selectors)('element %s is visible', (selector) => {
  cy.visit('/')
  cy.get(selector).should('be.visible')
})
Chriss
  • 5,157
  • 7
  • 41
  • 75