Надеясь, что кто-то может пролить свет на это, плохо знакомый с angular и rxjs.После обновления с Angular 5 до 7 и rxjs 5 до 6 я получаю несколько неудачных модульных тестов, которые прошли.
util.service.ts
handleError(error: HttpErrorResponse | any) {
let errors: any = [];
if (error instanceof HttpErrorResponse) {
if (error.status) {
switch (error.status) {
case 400:
errors = error.error.errors || '';
break;
case 401:
errors = [{ status: error.status, message: 'Please log in.' }];
return Observable;
case 403:
errors = [{ status: error.status, message: 'Access denied.' }];
break;
case 404:
errors = [{ status: error.status, message: 'The requested application is not found.' }];
break;
case 500:
errors = [
{ status: error.status, message: 'Sorry, we were unable to process your request. Please try again.' }
];
break;
default:
errors = [{ status: error.status }];
}
return throwError(errors);
}
}
try {
errors = error.error.errors;
return throwError(errors);
} catch (err) {
return throwError([
{ status: 500, message: 'Sorry, we were unable to process your request. Please try again.' }
]);
}
}
util.service.spec.ts
it('should throw an observable if response has status 404', () => {
const response = new HttpErrorResponse({ status: 404, error: { errors: ['error'] } });
expect(service.handleError(response)).toEqual(
throwError([{ status: 404, message: 'The requested application is not found.' }])
);
});
Ошибка кармы
Error: Expected $._subscribe = Function to equal Function.
at stack (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:2455:17)
at buildExpectationResult (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:2425:14)
at Spec.expectationResultFactory (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:901:18)
at Spec.addExpectationResult (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:524:34)
at Expectation.addExpectationResult (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:845:21)
at Expectation.toEqual (http://localhost:9876/absolute/Users/mtlaney/Desktop/coding_monkey/fs-open-forest-platform/frontend/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:2369:12)
at UserContext.it (http://localhost:9876/_karma_webpack_/webpack:/src/app/_services/util.service.spec.ts:59:43)
at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)
at ProxyZoneSpec.push../node_modules/zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/proxy.js:129:1)
at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:390:1)
Я изменил все с Observable.throw на rxjs new throwError.Любая помощь будет принята с благодарностью !!