【问题标题】:Cypress expect(false).to.equal(true) is true and Cypress skips cy.wait?赛普拉斯 expect(false).to.equal(true) 为真,赛普拉斯跳过 cy.wait?
【发布时间】:2023-01-12 00:45:59
【问题描述】:

我现在真的很困惑,不知道该怎么办。

赛普拉斯似乎对明显失败的测试没有问题,而且不会执行 cy.wait(10000);,正如您在图像右上角的时间戳中看到的那样。

我在 nx angular 项目中构建了一个 Cypress 组件测试。 这是测试和输出,我做错了什么?

After All 部分是因为有一个插件,没有它的行为相同。

/// <reference types="cypress" />

import { MatDialogRef } from "@angular/material/dialog";
import { CreateDiscussionPopUpComponent } from "./create-discussion-pop-up.component";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { MatInputModule } from "@angular/material/input";
import { SharedUtilitiesModule, MaterialModule } from "@xxx/shared-utilities";
import {
  TranslateLoader,
  TranslateModule,
  TranslateService,
} from "@ngx-translate/core";
import {
  TranslateLoaderMock,
  TranslateServiceTestProvider,
} from "@xxx/shared-services/mocks";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { FlexLayoutModule } from "@angular/flex-layout";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

const config = {
  imports: [
    TranslateModule.forRoot({
      loader: { provide: TranslateLoader, useClass: TranslateLoaderMock },
    }),
    FormsModule,
    BrowserAnimationsModule,
    ReactiveFormsModule,
    SharedUtilitiesModule,
    MaterialModule,
    MatInputModule,
    FlexLayoutModule,
  ],
  declarations: [CreateDiscussionPopUpComponent],
  providers: [
    {
      provide: MatDialogRef,
      useValue: {},
    },
    TranslateServiceTestProvider,
  ],
  schemas: [NO_ERRORS_SCHEMA],
};

describe("ISO-Akzeptanz-Test der CreateDiscussionPopUpComponent-Komponente", () => {
  let component: CreateDiscussionPopUpComponent;
  let fixture: ComponentFixture<CreateDiscussionPopUpComponent>;

  beforeEach((done) => {
    cy.viewport(750, 300);
    cy.mount(CreateDiscussionPopUpComponent, config).then((res) => {
      component = res.component;
      fixture = res.fixture;
      console.log(component + " " + fixture);

      const translateService = TestBed.inject(TranslateService);
      translateService.use("de");
      done();
    });
  });
  
  describe("ISO 171", () => {
    it("8.1.3", () => {
      cy.wait(10000);
      expect(false).to.equal(true);
    });

  });
});

在此先感谢您的帮助! ^^

【问题讨论】:

  • 这不是您的完整代码。显示 beforeEach 和 afterAll。
  • 添加了完整的 cy.ts 文件

标签: angular cypress nrwl cypress-component-test-runner


【解决方案1】:

Cypress 命令是异步的。 cy.wait() 不执行等待,赛普拉斯只是将该命令排入队列以便稍后执行。 这就是为什么您的断言在执行任何延迟之前运行的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多