gpt4 book ai didi

javascript - commands.js 中未定义 Cypress 和 cy,但一切正常

转载 作者:行者123 更新时间:2023-12-05 03:39:57 25 4
gpt4 key购买 nike

当在 commands.js 中输入自定义命令时,WebStorm 的 linter 说 Cypresscy 都未定义并且不提供任何 IntelliSense .两者都在任何 integration 文件中完美定义。

命令.js

Cypress.Commands.add('command', () => {
cy.get('div');
});

// ESLint: 'Cypress' is not defined.(no-undef)
// ESLint: 'cy' is not defined.(no-undef)

索引.js

import './commands.js'

这个错误不会出现在 VSCode 中。相反,Cypresscy 都被定义为 any

然而,不管这个错误,测试工作正常。

如何让 linter 在其自己的文件中识别 Cypress?

最佳答案

我找到了一些解决方案。

添加引用

把它放在每个文件测试脚本的顶部

/// <reference types="cypress" />

Eslint 扩展

{
"extends": [
"plugin:cypress/recommended"
]
}

在 eslintrc 全局变量中指定 cy
{
"globals": {
"cy": true
}
}

将此添加到 .eslintrc

cy is a global variable. Much like location. So really it is window.cy. You can add it to the globals in Eslint. Don't import cy from cypress.

引用:ESLint: 'cy' is not defined (Cypress)

关于javascript - commands.js 中未定义 Cypress 和 cy,但一切正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68337033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com