Skip to content

Commit

Permalink
fix(mockingbird-ts): fix plain functionality to work with primitives
Browse files Browse the repository at this point in the history
Fix plain functionality to be smarter and void destroying some primitives
  • Loading branch information
omermorad committed Aug 20, 2021
1 parent 0c2f550 commit 4fb5dcc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/mockingbird/src/lib/generator/mock-generator.ts
@@ -1,4 +1,4 @@
import { Class, ClassLiteral } from '@mockinbird/types';
import { Class, ClassLiteral, isPrimitive } from '@mockinbird/types';
import { ClassParser } from '@mockinbird/parser';
import { MockGeneratorOptions } from '../../types/mock-generator-options.interface';

Expand All @@ -10,8 +10,14 @@ export class MockGenerator {
private static classToPlain<TClass>(targetClass: TClass): ClassLiteral<TClass> {
const toPlain = (target: ClassLiteral<TClass>): ClassLiteral<TClass> => {
for (const key of Object.keys(target)) {
if (target[key] instanceof Object) {
target[key] = toPlain({ ...target[key] });
const value = target[key];

if (value instanceof Object) {
if (isPrimitive(value.constructor.name)) {
toPlain(value);
} else {
target[key] = toPlain({ ...value });
}
}
}

Expand Down

0 comments on commit 4fb5dcc

Please sign in to comment.