In my current project, I am working with Typescript on an AngularJS 1.X application. I make use of various Javascript libraries for different functionalities. While unit testing my code, I am interested in stubbing some dependencies using the Typings (interfaces). However, I want to avoid using the ANY type and do not want to create empty methods for each interface method.
I am searching for a solution that allows me to achieve something like this:
let dependency = stub(IDependency);
stub(dependency.b(), () => {console.log("Hello World")});
dependency.a(); // --> Compile, no action taken, no exception
dependency.b(); // --> Compile, print "Hello World", no exception
Currently, I am facing the dilemma of either using any
and implementing all methods called in my test cases or fully implementing the interface, resulting in excessive and unnecessary code.
Is there a way to generate an object with empty implementations for each method while maintaining typing? I currently utilize Sinon for mocking purposes but I am open to exploring other libraries as well.
PS: Despite being aware that Typescript erases interfaces, I am still determined to find a solution for this issue :).