title: Unit testing angular service, Injecting dependencies through beforeeach doesn't get executed
body: <p>I am trying to unit test a component that has a @viewChild component and few more services.</p>
  
  <p>Following is my spec.ts file. </p>
  
  <pre><code>  beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [ UpStoryComponent,ExperienceListComponent, MdToHtmlPipe, SafeUrlPipe, FormatUrlPipe, CurrencyFormatPipe, NoCommaPipe, MoneyPipe, SafeHtmlPipe],
        imports: [ FormsModule, HttpClientTestingModule, RouterTestingModule],
        providers: [{ provide: ActivatedRoute, useValue: {'params': Observable.from([{ 'id': 1}])}, ContentfulService, MatchingFlowService, FormDataService, LocalStorageService, ScrollService, Title, UpnorwayLoaderService, MoneyService, DayCalculatorService],
        schemas: [NO_ERRORS_SCHEMA]    
      }).compileComponents();
    });
  
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(UpStoryComponent);
      component = fixture.componentInstance;     
      component.experienceListComponent = TestBed.createComponent(ExperienceListComponent).componentInstance;
      fixture.detectChanges();
    });
  
    beforeEach(() =&gt; {
      contentfulService = TestBed.get(ContentfulService);
      spyOn(contentfulService, 'getEntryBySlug').and.callFake(function (args) {
        return of(blogPost);
      });
      fixture.detectChanges();
    });
  
  
    it('should create', () =&gt; { 
      expect(component).toBeTruthy();
    }); 
  </code></pre>
  
  <p>The last beforeeach statement gets executed, but does not inject service as expected. If I place the last beforeeach statement as the second beforeeach, then the current second beforeeach doesn't get executed as expected. </p>
  
  <p>There is no dependency between <code>ExperienceListComponent</code> and <code>ContentfulService</code>. But when injecting these two services through beforeach statements, only the first inject works, not the other. </p>
  
  <p>What could be the reason for this? Appreciate if you could provide a solution for this. </p>