首页 > 解决方案 > 赛普拉斯测试中的 Angular getHarness 不起作用

问题描述

我目前正在尝试启动和运行组件测试,并与角线束作斗争。在我的测试中,我想使用 MatPaginatorHarness(但我对它们都有同样的问题),但不幸的是 async/await 方法在 cypress 中不起作用。所以我用 Promise 试了一下。现在我收到以下错误:

Cypress detected that you returned a promise from a command while also invoking one 
or more cy commands in that promise.

The command that returned the promise was:

> cy.get()

The cy command you invoked inside the promise was:

> cy.log()
Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

代码是:

it('shows opens paginator', () => {
    const data: StudyStateModel[] = thirteenRows;
    const fixture = mount(DatatableComponent, {
        tableCols: TableColsConfig.STUDIES_COLS,
        tableData: data,
        activeEndpoint: apiEndpoints.STUDY
    });
    const loader = TestbedHarnessEnvironment.loader(fixture);
    
    loader.getHarness<MatPaginatorHarness>(MatPaginatorHarness).then((paginator) => {
        
        paginator.setPageSize(10);
        fixture.detectChanges();
        cy.get('.mat-row').should('have.length', 10);
        cy.get('.mat-row').should('not.be.visible');
        fixture.detectChanges();
        console.log(paginator);
        paginator.setPageSize(25);

        fixture.detectChanges();
    });

我知道我不应该使用承诺,因为赛普拉斯在这里告诉我,但我不知道该怎么做。只有在 promise 中有 cy.get 函数时才会出现问题。但我需要它们,因为我需要使用分页器。先感谢您。

标签: angulartypescriptcypressangular-test

解决方案


推荐阅读