我想用
cy.getByTestId(testId)
.should('have.attr', 'data-testStatus', 'OK')
.and('have.attr', 'opacity', '0');
和cy.getByTestId(testId)
让我这样:
<circle class="js-components-SvgFiles-SvgBearingBlock-___SvgBearingBlock__featureSelected___RhROg"
cx="66.5" cy="66.5" r="29.925" stroke-width="0" opacity="0" data-testStatus="OK" data-testid="fixedBearing_Circle"></circle>
但我总是收到此错误消息:
expected <circle.js-components-SvgFiles-SvgBearingBlock-___SvgBearingBlock__featureSelected___RhROg> to have attribute data-testStatus
为什么.should(
不使用外部html?
我已经测试了你的所有建议。不幸的是总是有相同的结果:
[1]: https://i.stack.imgur.com/yhUlu.png
这是用React编写的代码:
return (
<svg className={cn(style.svg, className)} width={size} height={size}
data-testid={blockType+'_'+( isLeftSide?'Left':'Right')} data-testStatus={testIdPlane}>
{feature}
{/* id of the bearing*/}
<text
className={colorText}
x={textPos}
y={size * 0.85}
textAnchor="middle"
fontSize={fontSize}
fontWeight="bold"
>
{text}
</text>
{dummyText}
</svg>
);
我刚刚意识到这样的事情:
cy.getByTestId('slidingBearing_Line')
.should('have.attr', 'opacity', '1')
.and('have.attr', 'y')
.should('gt', y);
工作中
无法重现以下内容:
describe('test', () => {
it('test', () => {
cy.document().then( doc => {
doc.body.innerHTML = `<circle class="js-components-SvgFiles-SvgBearingBlock-___SvgBearingBlock__featureSelected___RhROg"
cx="66.5" cy="66.5" r="29.925" stroke-width="0" opacity="0" data-testStatus="OK" data-testid="fixedBearing_Circle"></circle>`;
});
cy.get('[data-testid="fixedBearing_Circle"]')
.should('have.attr', 'data-testStatus', 'OK')
.and('have.attr', 'opacity', '0');
});
});
你能分享更多代码吗?