lundi 6 janvier 2020

Can you mock an interface with a constructor with ts-mockito

First I am not married to ts-mockito it's just what we are using.

That being said we have an interface that has a constructor we would like to mock and inject into another class for testing. Is this possible with ts-mockito.

No matter what I try I end up with the output that the mock is is not constructable.

Here's an example code that can produce the error

interface X {
  constructor(foo: string): any;
  bar: string;
}

const MockedX = mock<X>();
const mockedX1 = new MockedX();

Does anyone have any idea how to produce a mock on the fly?

Aucun commentaire:

Enregistrer un commentaire