Rub*_*lar 4 javascript reactjs cypress
我是 cypress 的新手,我正在尝试检查我的一个元素是否包含特定的样式。元素是这样的:
<div class="myElement" style="transform: translate(0%, 0px); "></div>
Run Code Online (Sandbox Code Playgroud)
这是我的断言:
cy.get('.myImage').should("have.css", "transform", "translate(0%, 0px)");
Run Code Online (Sandbox Code Playgroud)
这个断言不起作用,但我不知道为什么,cypress 说:
expected <div.myImage> to have CSS property transform with the value translate(0%, 0px), but the value was none
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Cypress'have.css 使用 chai-jquery断言计算值。
因此,即使您已经分配了translate(0%, 0px),它也会被计算为none。
或者,您可以像这样使用断言:
cy.get('.myImage').should('have.attr', 'style').should('contain', 'transform: translate(0%, 0px)')
Run Code Online (Sandbox Code Playgroud)