错误:超时-30000毫秒内未调用异步回调(由jasmine.DEFAULT_TIMEOUT_INTERVAL设置)

时间:2019-11-20 09:11:11

标签: angular jasmine karma-jasmine

无论我做什么,仍然无法使测试正确运行。尽管通过其他所有文章,我都尝试了所有可能的解决方案,但仍然无法正常工作。 设置jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;后,我认为它可以工作,但没有成功。 有什么想法可以解决这个问题吗?

describe('DashboardComponent', () => {
  let component: DashboardComponent;
  let fixture: ComponentFixture<DashboardComponent>;
  let therapistStatus = TherapistStatus;

  let id = '';
  let firstName = '';
  let lastName = '';
  let email = '';
  let status = 2;
  let statusChanges = '';
  let therapist = new Therapist({id, firstName, lastName, email, status, statusChanges});


  beforeEach(async(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
    TestBed.configureTestingModule({
      declarations: [ DashboardComponent],
      schemas: [NO_ERRORS_SCHEMA],
      imports: [
        RouterTestingModule,
        FormsModule,
        OAuthModule.forRoot(),
        ToastrModule.forRoot(),
        HttpClientTestingModule,
        ReactiveFormsModule,
        TranslateModule.forRoot()

      ],
      providers: [UserService]
    })
      .compileComponents().then(() => {
      fixture = TestBed.createComponent(DashboardComponent);
      component = fixture.componentInstance;
    });
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(DashboardComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create the dashboard component', () => {
    expect(component).toBeTruthy();

  });

1 个答案:

答案 0 :(得分:1)

您不需要使模块实例化异步。请尝试按照以下步骤删除和修改您的代码(请检查括号是否未填写)。希望这会有所帮助。

describe('DashboardComponent', () => {
  let component: DashboardComponent;
  let fixture: ComponentFixture<DashboardComponent>;
  let therapistStatus = TherapistStatus;

  let id = '';
  let firstName = '';
  let lastName = '';
  let email = '';
  let status = 2;
  let statusChanges = '';
  let therapist = new Therapist({id, firstName, lastName, email, status, statusChanges});


  beforeEach(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
    TestBed.configureTestingModule({
      declarations: [ DashboardComponent],
      schemas: [NO_ERRORS_SCHEMA],
      imports: [
        RouterTestingModule,
        FormsModule,
        OAuthModule.forRoot(),
        ToastrModule.forRoot(),
        HttpClientTestingModule,
        ReactiveFormsModule,
        TranslateModule.forRoot()

      ],
      providers: [UserService]
    }).compileComponents();
  fixture = TestBed.createComponent(DashboardComponent);
  component = fixture.componentInstance;
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(DashboardComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create the dashboard component', () => {
    expect(component).toBeTruthy();

  });