首页 > 其他 > 详细

[Cypress] Use the Most Robust Selector for Cypress Tests

时间:2019-06-17 23:55:03      阅读:203      评论:0      收藏:0      [点我收藏+]

Which selectors your choose for your tests matter, a lot. In this lesson, we‘ll see the recommended Cypress best practices for selectors, and why we should prefer the data-cy attribute.

 

If you know that for React, the best pratice for testing is also adding:

data-test-id={`todo-item-${todo.id}`}

 

For Cypress:

<li
   data-cy={"todo-item-" + todo.id}
   className={classnames({
      completed: todo.completed,
      diting: this.state.editing
  })}
 ></li>

 

spec:

cy.get("[data-cy=todo-item-3]")
      .should("have.text", "Hello world")
      .should("not.have.class", "completed")
      .find(".toggle")
      .should("not.be.checked");

 

[Cypress] Use the Most Robust Selector for Cypress Tests

原文:https://www.cnblogs.com/Answer1215/p/11042815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!