Angular APP_INITIALIZER for loading the configuration file in tests

I use this gist to read the configuration file during application startup. This works fine, but when I run unit tests, I get an error Cannot read property 'SomeProperty' of null.

I also added a provider for testing

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ LoginComponent ],
      imports: [ReactiveFormsModule, RouterTestingModule, HttpModule],
      providers: [AuthService,
        SettingsService,
        AppConfig,
        {
            provide: APP_INITIALIZER,
            useFactory: initConfig,
            deps: [AppConfig],
            multi: true
        },
        ]
    })
    .compileComponents();
  }));

Any pointers to resolve this issue. Thanks in advance.

+4
source share
1 answer

I turned the wheels a little on something like that. In the end, I simply expressed false information about the service in the "deps" of the provider APP_INITIALIZER and made sure that I did nothing in the unit tests.

Then you just check the initializer and the service yourself, and I think you can do it best.

0

Source: https://habr.com/ru/post/1676632/


All Articles