【问题标题】:Error: Timeout - Async callback was not invoked within 30000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)错误:超时 - 未在 30000 毫秒内调用异步回调(由 jasmine.DEFAULT_TIMEOUT_INTERVAL 设置)
【发布时间】:2019-11-20 09:11:11
【问题描述】:

无论我做什么,仍然无法使测试正常运行。尽管通过所有其他帖子我尝试了所有可能的解决方案,但仍然无法正常工作。 设置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();

  });

【问题讨论】:

    标签: angular jasmine karma-jasmine


    【解决方案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();
    
      });
    

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2017-07-24
      • 2020-05-13
      • 2020-01-07
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      相关资源
      最近更新 更多