我正试图将一个自定义命令添加到我的Cypress、Cucumber、Typescript测试框架中,但遇到了以下错误:
我在spec.ts
文件中收到此错误:Property 'seedLocalStorage' does not exist on type 'cy & EventEmitter'.
我在support/commands.ts
文件中收到此错误:Argument of type '"seedLocalStorage"' is not assignable to parameter of type 'keyof Chainable<any>'
以下是我的一些文件。
index.d.ts
:
declare namespace Cypress {
interface Chainable {
/**
* Custom command that seeds local storage with the following params:
* @param key
* @param value
*/
seedLocalStorage(key: string, value: string): Chainable;
}
}
support/commands.ts
:
Cypress.Commands.add('seedLocalStorage', (key, value) => {
return "some string for now"
})
tsconfig.json
:
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": [
"**/*.ts"
]
}
有人能告诉我我做错了什么吗;我该怎么解决这个问题?
我认为这是在说你需要返回一个值的Chainable包装器。
Cypress.Commands.add('seedLocalStorage', (key, value) => {
return cy.wrap("some string for now") // type Chainable<string>
})