I work with Typescript on an AngularJS 1.X project. I use different Javascript libraries for different purposes. To unit-test my source I would like to stub some dependencies using the Typings (= interfaces). I don't want to use the ANY-type and neither to write an empty method for each interface method.
Im looking for a way to do something like that:
let dependency = stub(IDependency);
stub(dependency.b(), () => {console.log(Hello World)});
dependency.a(); // --> Compile, do nothing, no exception
dependency.b(); // --> Compile, print Hello World, no exception
The pain I have right now, is that I either use any
and implement all methods which get called in my test case or I implement the interface and implement the full interface. That's too much useless code :(.
How can I generate an object that has an empty implementation for each method and is typed? I use Sinon for mocking purposes, but im open to use other libraries too.
PS: I know that Typescript erases the interfaces...but I still would like to solve that :).