为什么我的赛普拉斯 e2e 测试从未完成?

Why does my cypress e2e test never complete?

我有这个赛普拉斯 e2e 测试。

/// <reference types="Cypress" />

describe('Toss Full Test', function () {
let polyfill;
const uuid = Cypress._.random(0, 1e6)

before(() => {
    const polyfillUrl = 'https://unpkg.com/whatwg-fetch@3.0.0/dist/fetch.umd.js';
    cy.request(polyfillUrl).then(response => {
        polyfill = response.body;
    });
});
Cypress.on('window:before:load', win => {
    delete win.fetch;
    win.eval(polyfill);
});
const SubscribeEmail = "tosstests" + uuid + "@yopmail.com";
const SubscribePassword = "tossTests123456!!";
const SubscribeLogin = "tosstests" + uuid;

it('Full process', function (win) {
    cy.server();
    cy.visit("/");



    cy.route('POST', '/api/account/register').as('register');
    //this could be lagging as ravendb is starting
    cy.get("#LinkLogin", { timeout: 20000 }).click();
    //register
    cy.get("#LinkRegister").click();
    cy.get("#NewEmail").type(SubscribeEmail);
    cy.get("#NewName").type(SubscribeLogin);
    cy.get("#NewPassword").type(SubscribePassword);
    cy.get("#NewConfirmPassword").type(SubscribePassword);

    cy.window()
        .then(win => {
            // disables runCaptcha
            win.runCaptcha = new win.Function(['action'], 'return Promise.resolve(action)');
        })
        .then(
            () => {
                cy.get("#BtnRegister").click();
                cy.wait('@register');
                cy.get('@register').then(function (xhr) {
                    expect(xhr.status).to.eq(200);
                });

            }
        );
    })
})

可以在此处找到完整代码 https://github.com/RemiBou/Toss.Blazor/tree/master/Toss.Tests.E2E.Cypress

当我运行我的项目使用以下代码时

docker-compose up -V ravendb web
./node_modules/.bin/cypress open

代码 运行 很好,断言 "expect(xhr.status).to.eq(200);" returns 为真,但测试执行从未停止。这是为什么?

经过大量试验和错误后,我只需要从 "if" 调用中的方法中删除 "win" 参数,这是获取 window 引用的测试。实际上这个参数是你需要在测试结束时调用的回调,我找不到任何关于它的文档。