levibostian / ExpressjsBlanky

Blank Express.js project to get up and running FAST.
MIT License
7 stars 0 forks source link

Easy way to generate mocks #43

Open levibostian opened 4 years ago

levibostian commented 4 years ago

At this time, I am generating mocks manually in my code. The follow a very simple process:

interface Foo {
  bar(): string
}

class FooMock implements Foo {
  public barMock = jest.fn()

  bar: barMock
}

The problem is maintaining them. They are simply annoying to write which gets me to be lazy and not want to write them.

If there was a way to generate them automatically, that would be great. How do we do that?

FYI: handy ast viewer

levibostian commented 4 years ago

Here is a project that seems to do this: https://github.com/marchaos/jest-mock-extended

However, it has had a history of not being maintained and for some reason, it overrides the jest mock matcher API with Jasmine's. I am thinking of forking it and editing parts of it to be smaller and use the original jest matcher api.

See this issue for discussion around this.