Cypress 测试在应该失败的时候却通过了

问题描述 投票:0回答:1

我正在编写 Cypress 测试并在终端中无头运行它们。即使测试应该失败,但它们仍然通过了。

例如编写这段代码:

describe('Website Landing', () => {    
    it.only('Should load', async () => {
        cy.visit('http://www.mywebsite.com/');
        cy.get('[data-testid="sign-inx"]');
    })
})

在终端上运行此命令将成功结束:

cypress run

但是不存在具有这样的属性和值的元素。如果我在最后添加其他断言,测试就会继续通过

cy.get('[data-testid="sign-inx"]').should('have.length', 1);

我不明白赛普拉斯如何设法允许测试通过和失败。有人可以帮忙吗?

Cypress 版本是 13.15.1

enter image description here

javascript electron cypress chai
1个回答
0
投票

去掉

async
关键字。

这是使用和不使用它的相同运行。请注意时间上的差异,测试运行者似乎期待一些不会发生的事情。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.