cypress - 类型“cy & EventEmitter”上不存在属性“app”
问题描述
// spec/cypress/support/on-rails.ts
Cypress.Commands.add('app', function (name, command_options) {
return cy
.appCommands({ name: name, options: command_options })
.then((body) => {
return body[0];
});
});
spec/cypress/tsconfig.json
{
"compilerOptions": {
"strict": true,
"target": "es5",
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": false,
"types": ["cypress"],
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["**/*.ts"]
}
结果是
Property 'app' does not exist on type 'cy & EventEmitter'.
解决方案
相当老,但我最近遇到了这个问题。
这些文档显示了一种处理命令的方法。这是他们文档的链接:https ://docs.cypress.io/guides/tooling/typescript-support#Adding-child-or-dual-commands
赛普拉斯/支持/index.ts
// load type definitions that come with Cypress module
/// <reference types="cypress" />
declare global {
namespace Cypress {
interface Chainable {
/**
* Custom command to type a few random words into input elements
* @param count=3
* @example cy.get('input').typeRandomWords()
*/
typeRandomWords(
count?: number,
options?: Partial<TypeOptions>
): Chainable<Element>
}
}
}
赛普拉斯/支持/index.ts
Cypress.Commands.add('typeRandomWords', { prevSubject: 'element' }, (
subject /* :JQuery<HTMLElement> */,
count = 3,
options?
) => {
return cy.wrap(subject).type(generateRandomWords(count), options)
})
推荐阅读
- angular - Angular APP_INITIALIZER
- dart - 简化可迭代逻辑
- ruby-on-rails - 如何处理 Rails 连接表关系删除?
- if-statement - 当用户除以0时如何打印
- nginx - nginx: '/' url 不尝试 index.html 文件
- css - 资源 CSS 在 Intellij IDEA 中的 JSF 中不起作用
- functional-programming - “报价”显示在输出中,同时在 Scheme 中附加左折叠
- opencl - 如何解决 Debian 上的 CL_INVALID_BUILD_OPTIONS 问题?
- javascript - Next.js 页面过渡
- vbscript - 使用 VBS 查找进程 ID