Skip to content
Snippets Groups Projects
Commit a24ad607 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3563 fix tests and new mocking function

parent a11d104f
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { Type } from '@angular/core'; import { Type } from '@angular/core';
import { isNil } from 'lodash-es';
// Cannot find namespace 'jest'.ts(2503) // Cannot find namespace 'jest'.ts(2503)
// Exported type alias 'Mock' has or is using private name 'jest' // Exported type alias 'Mock' has or is using private name 'jest'
...@@ -31,7 +32,7 @@ export function mock<T>(service: Type<T>): Mock<T> { ...@@ -31,7 +32,7 @@ export function mock<T>(service: Type<T>): Mock<T> {
const mockValue = {} as Mock<T>; const mockValue = {} as Mock<T>;
let currentPrototype = service.prototype; let currentPrototype = service.prototype;
while (currentPrototype && currentPrototype !== Object.prototype) { while (!isNil(currentPrototype) && currentPrototype !== Object.prototype) {
Object.getOwnPropertyNames(currentPrototype) Object.getOwnPropertyNames(currentPrototype)
.filter(isFunctionDescriptor(currentPrototype)) .filter(isFunctionDescriptor(currentPrototype))
.forEach((key) => { .forEach((key) => {
...@@ -59,7 +60,7 @@ export function mock2<T>(service: Type<T>): Mock<T> { ...@@ -59,7 +60,7 @@ export function mock2<T>(service: Type<T>): Mock<T> {
function isFunctionDescriptor(prototype: object) { function isFunctionDescriptor(prototype: object) {
return (key: string) => { return (key: string) => {
const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key); const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
return descriptor?.value && typeof descriptor.value === 'function'; return !isNil(descriptor) && !isNil(descriptor.value) && typeof descriptor.value === 'function';
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment