You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 10:55:57