【发布时间】:2018-08-05 12:15:59
【问题描述】:
我正在 TypeScript 中实现自定义 Cypress 命令:
// support/commands.ts
const login = () => {
console.log('Logging in...');
};
Cypress.Commands.add('login', login);
declare namespace Cypress {
interface Chainable {
login: typeof login;
}
}
我尝试使用:
describe('Login Scenario', () => {
it('should allow a user to login', () => {
cy.visit('/');
cy.login();
});
});
但是,命令似乎没有设置:
TypeError: cy.login is not a function
如果我用纯 JavaScript 编写命令(删除命名空间声明并将调用更新为 (cy as any).login();,它可以工作。
我错过了什么?
【问题讨论】:
-
您的
support/commands.js是否包含在您的support/index.js中? -
有什么适合你的答案吗?
-
导入'./commands';在 support/index.ts
标签: typescript cypress