sco*_*147 25 javascript typescript cypress
所以我尝试在 cypress (commands.js 文件)中添加自定义命令,如下所示:
\n Cypress.Commands.add("login", (email, password) => {\n cy.intercept(\'POST\', \'**/auth\').as(\'login\');\n cy.visit(\'/auth\');\n cy.get(\'[formcontrolname="email"]\').type(email);\n cy.get(\'[formcontrolname="password"]\').type(password);\n cy.get(\'form\').submit();\n cy.wait(\'@login\').then(xhr => {\n expect(xhr.request.body.email).to.equal(email);\n expect(xhr.request.body.password).to.equal(password);\n });\n });\nRun Code Online (Sandbox Code Playgroud)\n但我收到此错误:
\n\'参数类型字符串不可分配给参数类型 keyof Chainable ... \xc2\xa0\xc2\xa0Type 字符串不可分配给类型“and” | “作为”| “选择文件” | “模糊”| “检查”| “孩子们”| “清晰”| “清除Cookie”| “清除Cookies” | “清除本地存储”| “点击”| ... \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Type 字符串不可分配给类型“intercept”\'
\n我发现这个问题Argument type string is not assignable to parameter type keyof Chainable... in Cypress,但这里的答案仅适用于 index.d.ts 文件,但是我有一个 index.js 文件(cypress版本 10.3.0 这对我不起作用。有人能帮我解决这个问题吗?
\nFod*_*ody 40
你不应该在 Typescript 项目中混合使用.js和。.ts
创建所有内容.ts,然后添加index.d.ts自定义命令的类型定义。
/// <reference types="cypress" />
declare namespace Cypress {
interface Chainable<Subject = any> {
login(): Chainable<any>;
}
}
Run Code Online (Sandbox Code Playgroud)
您可能会遇到更多问题,例如检查文件夹tsconfig.json中是否有/cypress.
如果有疑问,请使用cypress-realworld-app作为 Typescript 设置的参考。
| 归档时间: |
|
| 查看次数: |
19990 次 |
| 最近记录: |