0

I am writing the unit test cases for the Angular 8 app. This is the hybrid application with AngularJs + Angular 8.

I'm getting following error:

NullInjectorError: StaticInjectorError(DynamicTestModule)[TestService -> $injector]: 
  StaticInjectorError(Platform: core)[TestService -> $injector]: 
    NullInjectorError: No provider for $injector!

I'm not sure, how to mock $injector class. I tried the mock the TestService, I won't be able to cover some integration test cases in that scenario.

Any help in mocking $injector class would be appreciated.

Neeraj Shende
  • 310
  • 1
  • 7

2 Answers2

0

You can create a mock object for $injector . I had faced a similar issue for $rootscope in my project where I provided an empty object for $rootscope using Angular provider :

    {provide: '$rootScope',useValue : {}}

This provider will be part of TestBed configuration like this :

    beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [],
          imports: [],
          providers : [{provide: '$rootScope',useValue : {}}]
        })
          .compileComponents();
      }));

You can provide any dummy value as per your requirement instead of the empty object for useValue.

-1

Its a syntax error, TestService import right component/module. for more information "https://angular.io/start"