使用ESLint Cypress插件时cy仍未定义的问题排查
Cypress组件测试ESLint类型报错问题
我用Cypress做组件测试时,按官方文档自动生成了component-index.html和components.ts文件,只在components.ts里加了util/i18n和Tailwind CSS的配置。写完Button组件的测试文件Button.cy.tsx后,ESLint报了这个错:
Cannot find name 'cy'. ts(2304)
但测试实际跑起来是正常的。
我试过这些方法都没用:
- 安装了
eslint-plugin-cypress - 在
.eslintrc.json里配置了extends和plugins - 手动加了
globals配置
后来我在测试文件顶部手动加/// <reference types="cypress" />,能消掉cy未定义的报错,但又冒出来新的类型错误:
Property 'mount' does not exist on type 'cy & CyEventEmitter'. ts(2339)
我不想在每个测试文件里都手动加这种声明,想找个一劳永逸的解决办法。
相关依赖版本
cypress: "12.7.0"cypress-mochawesome-reporter: "3.3.0"cypress-multi-reporters: "1.6.2"eslint-plugin-cypress: "^2.14.0"
内容的提问来源于stack exchange,提问作者Mähnenwolf
相关产品推荐
相关产品推荐

