When I run TypeScript lint, it doesn't seem to be recognizing cypress-testing-library commands
See original GitHub issuecypress-testing-library
version: 8.0.3node
version: 16.15.0npm
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:
- Created a year ago
- Reactions:5
- Comments:7
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 ofcypress/support/e2e.ts
(ORcypress/support/commands.ts
)One solution worked for me. Use reference comments on the top of your test files:
/// <reference types="cypress" />
/// <reference types="@testing-library/cypress" />