当在 beforeEach 中使用异步时,测试中的所有操作都会触发两次

All actions in test are fired twice when async is used in beforeEach

我正在为 Angular 应用编写 E2E 测试,但是测试中调用的所有操作都会触发两次。

我已经尝试删除我以前使用的所有自定义命令。

describe('some tests', () => {
beforeEach(async() => {
    const data = {
        'data':'someData'
    }
    cy.visit('url');
    const window = await cy.window();
    window.postMessage(JSON.stringify(data), '*');
})

it('test1', () => {
    cy.get('#login-field').type('email', {force: true});
    cy.get('#password-field').type('password', {force: true});
    cy.get('#login-button').click({force: true});
})

})

使用

{force: true} 是因为在 parents.

之一中,赛普拉斯将它们报告为不可见,因为 overflow: hidden

我希望每个动作都被触发一次,但它们被触发了两次并同时执行,例如输入 'email' 会触发两次,并且会在字段中输入 'eemmaaiill' 而不是 'email'.

如果有人想知道:这是 Cypress 的问题,如果我们在 beforeEach 中使用 async,那么测试中的操作将执行两次。当前的解决方案是不使用 async 或移动使用它来测试自己的代码。