小编ole*_*k91的帖子

Cypress getByTestId、queryByTestId、findByTestId 检查元素是否不存在

我正在尝试使用 Cypress 和testing-library/cypress 检查 DOM 树中是否不存在元素。

如果我尝试cy.getByTestId("my-button").should("not.exist")测试失败,因为它找不到元素。

如果我cy.findByTestId("my-button").should("not.exist")这样做也会因为超时而失败。

cy.queryByTestId("my-button").should("not.exist")如果我执行以下任一操作,则测试确实有效

cy.get('[data-testid="my-button"]').should("not.exist")

有人可以解释一下这4个有什么区别吗?

谢谢

javascript testing integration-testing end-to-end cypress

8
推荐指数
1
解决办法
2万
查看次数