question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When I run TypeScript lint, it doesn't seem to be recognizing cypress-testing-library commands

See original GitHub issue
  • cypress-testing-library version: 8.0.3
  • node version: 16.15.0
  • npm version: 8.5.5

Relevant code or config:

tsconfig.json file

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "dom"],
    "types": ["cypress", "@testing-library/cypress"]
  },
  "include": ["**/*.ts"]
}

At top of spec files I am trying to lint, I have put the following code:

// @ts-check

in commands.js I have included

import '@testing-library/cypress/add-commands';

What you did: I am following Gleb’s instructions on converting Cypress from JavaScript to TypeScript. So all my files are still .js but I have it set up for TypeScript to check types as seen above. I’m now running the lint command on a few of my spec files to see what errors occur. I am doing the lint via a script that runs the command line: tsc --noEmit --pretty --allowJs --resolveJsonModule

What happened: I received type errors for cypress-testing-library commands:

Property ‘findByRole’ does not exist on type ‘cy & CyEventEmitter’. Property ‘findByLabelText’ does not exist on type ‘cy & CyEventEmitter’

This is for all occurrences of those methods in the spec file

Problem description: I followed the setup given on this GitHub for getting typescript to work with cypress-testing-library, so I would expect these types to be recognized.

Suggested solution: Not sure - maybe I am missing something obvious in the set-up?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

4reactions
wingy3181commented, Sep 28, 2022

Another solution is as per https://zudemwango.medium.com/how-to-setup-cypress-testing-library-cypress-with-typescript-ac401a604d74 and i just added /// <reference types="@testing-library/cypress" /> to the top of cypress/support/e2e.ts (OR cypress/support/commands.ts)

1reaction
phollakicommented, Sep 21, 2022

One solution worked for me. Use reference comments on the top of your test files: /// <reference types="cypress" /> /// <reference types="@testing-library/cypress" />

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - Cypress Documentation
Cypress ships with official type declarations for TypeScript. This allows you to write your tests in TypeScript. Install TypeScript To use TypeScript.
Read more >
Cypress Testing Library
Cypress Testing Library extends Cypress's cy commands. ... You can now use all of DOM Testing Library 's findBy , findAllBy , queryBy...
Read more >
ESLint: 'cy' is not defined (Cypress) - Stack Overflow
It runs in Cypress just fine. But I get Typescript errors in Webstorm, saying that cy is not defined (a TS and ESlint...
Read more >
How To Setup Cypress + @testing-library/cypress ... - Medium
Start your project by running yarn start and then open cypress by running yarn cypress in the terminal. When cypress successfully runs, the...
Read more >
My struggles with React Testing Library - Hao's learning log
It seems like the right thing to do. Especially when Cypress tests running in parallel were taking over 40 mins to complete. So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found