mercredi 18 novembre 2020

Why TestBed beforeeach uses waitForAsync instead of just async/await compileComponents?

In Angular tests the usual thing is to do this for the beforeEach method

beforeEach(waitForAsync(() => {
  TestBed
      .configureTestingModule({
        declarations: [BannerComponent],
      })
      .compileComponents();  // compile template and css
}));

What's the difference with doing the following ?

beforeEach(async () => {
  await TestBed
      .configureTestingModule({
          declarations: [BannerComponent],
      })
      .compileComponents();  // compile template and css
});

I tried to find an explanation in the docs but couldn't figure it out.

https://angular.io/api/core/testing/waitForAsync#description https://v10.angular.io/guide/testing-components-scenarios#the-async-beforeeach

Aucun commentaire:

Enregistrer un commentaire