Closed ghsatpute closed 4 years ago
Hey, there is no possibility to do that. You can create ThirdPartyClassFactory
with create
method and mock this create
method. But mocking new
is not possible.
I think it would be a great addition. There can be many new instance creations and we cannot keep creating a factory for each one.
Also, I, personally, don't like my main code to change because I cannot write test cases.
But there is no way to override new
in JS. Only test runners like jest
can do that during code analyze / transpilation. ts-mockito
is just runtime lib and cannot change how JS works.
I have a code which I want to test as below
I want to mock
new ThirdPartyClass()
instance creation? How do I do that in TypeScript Mockito?