-1

I have started writing test cases for Angular and while reading articles from internet I found there are different ways in which we can configure our TestBed. Below are few examples:

Example 1:

beforeEach(async(() => {
  TestBed.configureTestingModule({
   ...
  }).compileComponents()
    .then(() => {
      fixture = TestBed.createComponent(Component);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
}));

Example 2:

beforeEach(async(() => {
  TestBed.configureTestingModule({
   ...
  }).compileComponents();
}));
beforeEach(() => {
  fixture = TestBed.createComponent(Component);
  component = fixture.componentInstance;
  fixture.detectChanges();
});

Example 3:

beforeEach(async(() => {
  TestBed.configureTestingModule({
   ...
  }).compileComponents();
  fixture = TestBed.createComponent(Component);
  component = fixture.componentInstance;
  fixture.detectChanges();
}));

Example 4:

beforeEach(async() => {
  TestBed.configureTestingModule({
   ...
  });
  await TestBed.compileComponents();
  fixture = TestBed.createComponent(Component);
  component = fixture.componentInstance;
  fixture.detectChanges();
});

I need help to understand which is the recommended approach to follow?

Aakash Goplani
  • 1,150
  • 1
  • 19
  • 36

1 Answers1

0

If all of them work, you can pick your favorite. I personally use Example 2 since that's how I see it being done most places.

AliF50
  • 16,947
  • 1
  • 21
  • 37