我试着在我的Azure发布管道中运行Cypress。我在本地安装了所有的软件包,但是当我运行Cypress测试时,我得到了几个错误:
TypeError: cy.visit(.).getByText不是函数 TypeError: cy.getByLabelText不是一个函数 TypeError: cy.getByPlaceholderText不是一个函数
我将以下包添加到我的package.json devDependencies部分:
"@testing-library/cypress": "^4.0.4",
"@testing-library/react": "^8.0.4",
"@testing-library/dom": "latest",知道为什么Cypress会返回这些TypeErrors吗?
这是笔试的一个例子:
it("can request to join private team", () => {
const privateTeamId = "fe1fa897-2e90-4ecb-91f9-0c9bb33ef63a";
cy.get(`[id=${privateTeamId}]`)
.click()
.getByText("Request membership")
.click()
.getByText("Membership request sent");
});发布于 2019-07-13 16:22:51
您需要扩展Cypress的cy命令。
只需将此import '@testing-library/cypress/add-commands';行添加到项目的cypress/support/commands.js中即可
添加这一行之后,如果它仍然不能工作,那么关闭Cypress并重新启动它。
发布于 2021-03-03 14:17:41
在我的例子中,我发现在测试库+ Cypress之间的集成中不存在getBy*查询。
所以我刚从cy.getByText迁移到cy.findByText,一切都正常。
根据医生的说法:
注意: get*查询不受支持,因为对于合理的Cypress测试,您需要重约性,而find*查询已经支持这一点。查询*查询自v5以来不再是必要的,将在v6中删除。完全支持内置的Cypress断言(删除查询的唯一用例*)。
https://testing-library.com/docs/cypress-testing-library/intro
https://stackoverflow.com/questions/57014021
复制相似问题