英文:
Cypress version 12.14.0 just cannot find command files with Typescript
问题
我正在尝试在我的Cypress测试中使用TypeScript包含自定义命令。似乎很难让它工作。我已经将文件移动到各种文件夹中,但这只是一次令人沮丧的体验。不应该这么难。这是我的项目结构:
在我的support文件夹中,我有以下文件:
cypress
support
e2e.ts
index.d.ts // 声明Cypress命名空间并定义命令的定义
accounts-cmd.ts // 包含Cypress.Command.add(.....)的文件
fixtures
tests // 我的测试在这里
accounts.cy.ts // 使用自定义命令findByAccountsId(id: string)
// tsconfig.json
types: ["cypress", "./support"]
// cypress.config.ts
supportFile: "./support/e2e.ts"
在index.d.ts中,我声明了一个叫做findAccountsById(id: string)的命令,它返回一个Chainable
findByAccountId(id: string): Chainable<Response>;
在我的accounts-cmd.ts中,我引用了index.d.ts:
/// <reference path="./index.d.ts" />
英文:
I am attempting to include custom commands in my Cypress tests using typescript. It just seems so difficult to get it to work. I have moved the files in various folders but it is simply a frustrating experience. It shouldn't be this hard. Here is the structure of my project: I am using version 12.14.0 of Cypress and Typescript
In my support folder, I have the following files
cypress
support
e2e.ts
index.d.ts. // declare namespace Cypress with definitions of commands
accounts-cmd.ts // has Cypress.Command.add(.....)
fixtures
tests // my tests are in here
accounts.cy.ts // uses custom command findByAccountsId(id: string)
//tsconfig.json
types: ["cypress", "./support"]
//cypress.config.ts
supportFile: "./support/e2e.ts",
I have my a declaration in the index.d.ts called findAccountsById(id: string) which returns a Chainable<Response> from and axios call. It is defined like this
findByAccountId(id: string): Chainable<Response>;
In my accounts-cmd.ts I reference the index.d.ts
/// <reference path="./index.d.ts" />
答案1
得分: 4
我认为你想要将引用放在tsconfig.json
的includes: []
属性中。
请参考cypress-real-world-app中的示例:
{
...
"include": ["./**/*.ts"], // 包括 /cypress/support/index.d.ts
...
}
我理解"types"键用于节点模块,而不是你自己的类型。
英文:
I think you want to put the reference in includes: []
property of tsconfig.json
.
{
...
"include": ["./**/*.ts"], // catches /cypress/support/index.d.ts
...
}
My understanding is that "types" key is for node modules, not your own types.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论