evangalen / ng-improved-testing

Improves AngularJS testing
MIT License
21 stars 4 forks source link

Support mocking of Typescript classes #20

Open brp-magnusd opened 9 years ago

brp-magnusd commented 9 years ago

We are using ng-improved-testing together with Typescript. It works great for most things!

Though: When creating a mock of a TypeScript class one has to use: mockInstance(FooClass.prototype) instead of just mockInstance(FooClass).

This would be nice as it increases readability.

evangalen commented 9 years ago

The idea behind mockInstance is to create a mock object of an existing object instance. In your particular case you would like a mock object that first instantiates and object from a constructor and the uses the creates object as a template to create the mock object.

I previously though about creating such a (global) mock method but finally decided against it. My rationale was that in that could you could also just with: mockInstance(new FooClass());

Instead of using mockInstance(FooClass.property) I would suggest using mockInstance(new FooClass()) instead. This way you also include the properties declared on the FooClass instance itself, otherwise you only include those on the prototype.