vitalishapovalov / jest-decorated

Decorators library for writing jest-based tests
https://vitalishapovalov.github.io/jest-decorated/
MIT License
49 stars 4 forks source link

Is there a way to make it run the constructor? #436

Open donnyroufs opened 1 year ago

donnyroufs commented 1 year ago

Hey 👋

I would like to share a test suite so that I do not need to create the same one with different dependencies, but it does not seem to be 'possible' since it does not run the constructor.

The base class that contains the tests image

Using inheritance:

export class CreateTaskShould extends BaseCreateTask {
  public constructor() {
    const fakeRepo = new FakeTaskRepository()
    const db = new TestDatabaseClient(fakeRepo)
    super(db, fakeRepo)
  }
}

results in dependencies being undefined because the constructor is never ran. Now another solution would have been to make "BaseCreateTask" abstract but then the decorators won't work.