jest-decorated icon indicating copy to clipboard operation
jest-decorated copied to clipboard

Is there a way to make it run the constructor?

Open donnyroufs opened this issue 1 year ago • 0 comments

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.

donnyroufs avatar Mar 16 '23 11:03 donnyroufs