omermorad / mockingbird

🐦 Decorator Powered TypeScript Library for Creating Mocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: when calling MockFactory.create(...) return a new instance instead of plain object

omermorad opened this issue · comments

Today (as of version 1.1.1), when calling the .create() method, Mockingbird simply returns a plain object which also has a type definition as well - it looks like this:

type ClassLiteral<TClass extends any = any> = { [K in keyof TClass]: TClass[K] };

Where the return type of .create() is ClassLiteral<T>

Sometimes we will want to have back an actual instance of the class (and not a plain object) for different purposes; One that I can think of is when we use a model that contains logic.

Another option is maybe to always return an instance of the class but enable the user to ask for a plain object instead, using a chained method:

MockFactory.create(...).toPlain()