Git Product home page Git Product logo

mockingbird's Introduction

Hey There ๐Ÿ‘‹

My name is Omer, a tech lead and backend maestro specializing in Node, TypeScript, and NestJS. Beyond coding, I love sharing my knowledge as a public speaker. I'm on a relentless mission to push the boundaries of software engineering. Driven by this fervor, I created Automock, a clear reflection of my obsession for quality.

https://github.com/automock/automock

mockingbird's People

Contributors

iamjoeker avatar idanpt avatar omer-morad-ni avatar omermorad avatar ptichi avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mockingbird's Issues

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

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()

enhancement: mock different values based on other fields

Sorry for opening another issue. But i need to generate a different values depending on another fields, example:

export class Example {
  @Mock()
  isActive: boolean;

  @Mock() // Should only be defined if isActive is false.
  deactivationReason?: string;
}

So, it would be cool if i could write something like that:

export class Example {
  @Mock()
  isActive: boolean;

  @Mock((faker, self) => self.isActive ? null : faker.someMethod())
  deactivationReason?: string;
}

Where data is what is already generated, like isActive (Probably depends on execution / field order) because it was declared first.

Also, if it is possible, you also could add the hability to return promises.

Thanks for making this amazing library!

Suggestion: create 'pick' functionality to pick only what's needed

Add new functionality to enable to pick only what's needed in the generated mock, here is an example:

class Bird {
  @Mock((faker) => faker.random.uuid())
  uid: string;

  @Mock((faker) => faker.name.firstName())
  name: string;
  
  @Mock()
  canFly: boolean;
}

const mock = MockFactory<Bird>(Bird).pick('uid', 'name').one();

bug: using `null` or `undefined` as the `@Mock(() => result)` throws error

If i use null or undefined as the @Mock(() => result), it throws:

    TypeError: Cannot convert undefined or null to object
        at Function.getOwnPropertyNames (<anonymous>)

      at getClassMembers (../../../node_modules/@plumier/reflect/lib/parser.js:87:28)
      at parseMethods (../../../node_modules/@plumier/reflect/lib/parser.js:134:21)
      at parseClassNoCache (../../../node_modules/@plumier/reflect/lib/parser.js:173:18)
      at ../../../node_modules/@plumier/reflect/lib/helpers.js:18:31
      at walkTypeMembers (../../../node_modules/@plumier/reflect/lib/walker.js:35:45)
      at walkTypeMembersRecursive (../../../node_modules/@plumier/reflect/lib/walker.js:54:23)
      at reflectClass (../../../node_modules/@plumier/reflect/lib/reflect.js:15:55)
      at reflectModuleOrClass (../../../node_modules/@plumier/reflect/lib/reflect.js:66:16)
      at ../../../node_modules/@plumier/reflect/lib/helpers.js:18:31

Originally posted by @arthurfiorette in #135 (comment)

Bug: MackFactory .plain() option return partial plain nested object

Consider the following example:

import { Mock, MockFactory } from 'mockingbird-ts';

export class Dog {
  @Mock((faker) => faker.name.firstName())
  name: string;

  @Mock()
  snacks: number;
}

export class User {
  @Mock((faker) => faker.random.uuid())
  id: string;

  @Mock((faker) => faker.internet.email())
  email: string;

  @Mock((faker) => faker.name.firstName())
  name: string;

  @Mock()
  birthday: Date;
  
  @Mock({ type: Dog, count: 3 })
  dogs: Dog[];
}

const oneUser = MockFactory<User>(User).plain().one();

oneUser is in fact a plain object, but(!), the dogs property (which is an array of Dogs) contains an array of instances of Dog and not an object literal.

Thoughts - The bug can be fix simply by refactoring the @mockinbird/parser package

Installation of v1.1.0 failing due to husky call in postinstall script

I went to update to the new release this evening. Install is now failing due to the postinstall script which calls husky. Husky docs recommend using the prepare script.

bash$ yarn add mockingbird-ts   

yarn add v1.22.10
[1/5] ๐Ÿ”  Validating package.json...
[2/5] ๐Ÿ”  Resolving packages...
[3/5] ๐Ÿšš  Fetching packages...
[4/5] ๐Ÿ”—  Linking dependencies...
[5/5] ๐Ÿ”จ  Building fresh packages...
[9/14] โ   fsevents
[12/14] โ   core-js
[3/14] โ   canvas
[13/14] โ   mockingbird-ts
error /app/node_modules/mockingbird-ts: Command failed.
Exit code: 127
Command: husky install
Arguments: 




bash$ 

Suggestion: add ability of data persistence in mock factory

Today, the common use of Mockingbird looks like this

MockFactory.create<User>(UserEntity, { count: 3 });

The data is often used for seeding a database or simply just to generate fixtures for integration tests.

I suggest adding the option to persist the data into a file, exactly like Jest is doing with Snapshot, for example:

MockFactory.create<User>(UserEntity, { count: 3 }).persist();

(can be also .snapshot(), needs to decide what's better)

The data has to be saved in a JSON file and needs to have a unique name - maybe the class/test file name. There is also another option - to pass a parameter to the persist() method with a unique slug:

MockFactory.create<User>(UserEntity, { count: 3 }).persist('simple-user-mock');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.