У меня есть служба, у этой службы есть функция загрузки, я хочу проверить эту функцию и получить ошибку. 'Ошибка типа: _this.handler.handle не является функцией'
Это мой Сервис, этот сервис работает без проблем.
export class AppConfigService {
static settings: IAppConfig;
constructor(private http: HttpClient) {}
load() {
const jsonFile = `assets/config/config.${environment.name}.json`;
return new Promise<void>((resolve, reject) => {
this.http.get(jsonFile).toPromise().then((response: IAppConfig) => {
AppConfigService.settings = response as IAppConfig;
resolve();
}).catch((response: any) => {
console.log(response);
reject(`Could not load file '${jsonFile}': ${JSON.stringify(response)}`);
});
});
}
}
и это мой тест
describe('AppConfigService', () => {
let service: AppConfigService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AppConfigService,
HttpClient,
HttpHandler,
HttpBackend,
]});
service = TestBed.get(AppConfigService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('should ran load well', () => {
service.load();
});
});
тогда я получаю эту ошибку:
TypeError: _this.handler.handle is not a function
TypeError: _this.handler.handle is not a function
at MergeMapSubscriber.project (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/common/fesm5/http.js:1046:62)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:61:1)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:51:1)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:54:1)
at Observable._subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/observable/scalar.js:5:1)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Observable.js:43:1)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Observable.js:29:1)
at MergeMapOperator.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapOperator.call (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:29:1)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Observable.js:24:1)
at FilterOperator.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterOperator.call (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/operators/filter.js:15:1)
Я думаю, что в тестовом коде я неправильно ввел сервис, но я не знаю, как решить эту проблему.