From a24ad6077bed39541ef0f2df43ccfbe95771b504 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 17 Dec 2024 16:00:44 +0100
Subject: [PATCH] OZG-3563 fix tests and new mocking function

---
 alfa-client/libs/test-utils/src/lib/mocking.ts | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/alfa-client/libs/test-utils/src/lib/mocking.ts b/alfa-client/libs/test-utils/src/lib/mocking.ts
index 0dd014c12f..a719f7c6b5 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';
   };
 }
 
-- 
GitLab