1

I was set up the angular project with the jest unit testing framework and after running the test case it's throwing me an error.

TypeError: Cannot read property 'injector' of null

app.component.spec.ts

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('AppComponent', () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;
  beforeEach(async () => {
    TestBed.configureTestingModule({
      declarations: [AppComponent],
      imports: [HttpClientTestingModule],
    }).compileComponents();
  });

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

  it(`should have as title 'Angular-unitTest'`, () => {
    expect(AppComponent).toBeTruthy();
  });
});

Let me know if you need more information to figure out where is the problem.

screenshot of error

Thanks

Rahil
  • 71
  • 2
  • 8
  • possible duplicate of https://stackoverflow.com/questions/40699593/cannot-read-property-injector-of-null-jasmine-angular-2 – Bharath S Sep 24 '21 at 10:01
  • @BharathS I already tried that but did not resolve this error. And I think that for Jasmin karma. I have setup jest unit testing framework – Rahil Sep 24 '21 at 10:15
  • Can you add RouterTestingModule to your imports in the test... – Owen Kelvin Sep 24 '21 at 10:46

0 Answers0