diff --git a/alfa-client/libs/test-utils/src/lib/mocking.ts b/alfa-client/libs/test-utils/src/lib/mocking.ts index 0dd014c12fa0957192fbca2d4ac34143896e9108..a719f7c6b56b0ed0495b8d8970ecf0cc7f6d6ed5 100644 --- a/alfa-client/libs/test-utils/src/lib/mocking.ts +++ b/alfa-client/libs/test-utils/src/lib/mocking.ts @@ -22,6 +22,7 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { Type } from '@angular/core'; +import { isNil } from 'lodash-es'; // Cannot find namespace 'jest'.ts(2503) // Exported type alias 'Mock' has or is using private name 'jest' @@ -31,7 +32,7 @@ export function mock<T>(service: Type<T>): Mock<T> { const mockValue = {} as Mock<T>; let currentPrototype = service.prototype; - while (currentPrototype && currentPrototype !== Object.prototype) { + while (!isNil(currentPrototype) && currentPrototype !== Object.prototype) { Object.getOwnPropertyNames(currentPrototype) .filter(isFunctionDescriptor(currentPrototype)) .forEach((key) => { @@ -59,7 +60,7 @@ export function mock2<T>(service: Type<T>): Mock<T> { function isFunctionDescriptor(prototype: object) { return (key: string) => { const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key); - return descriptor?.value && typeof descriptor.value === 'function'; + return !isNil(descriptor) && !isNil(descriptor.value) && typeof descriptor.value === 'function'; }; }