我是 cypress 的新手,我正在尝试检查我的元素之一是否包含特定样式。该元素是这样的:
<div class="myElement" style="transform: translate(0%, 0px); "></div>
这是我的断言:
cy.get('.myImage').should("have.css", "transform", "translate(0%, 0px)");
这个断言是行不通的,但我不明白为什么, Cypress 说:
expected <div.myImage> to have CSS property transform with the value translate(0%, 0px), but the value was none
我做错了什么?
最佳答案
Cypress 的 have.css
uses chai-jquery其中断言 computed value .
因此,即使您分配了 translate(0%, 0px)
,它也会被计算为 none
。
或者,您可以像这样使用断言:
cy.get('.myImage').should('have.attr', 'style').should('contain', 'transform: translate(0%, 0px)')
关于javascript - 用 Cypress 检查变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53923965/