NOTE: ngImprovedTesting is AngularJS library to make mock testing AngularJS code more easy.
For more information about ngImprovedTesting be sure to read its (updated) introductory blog post.
Just released version 0.3 ngImprovedTesting with a much improved ModuleBuilder.
Prior to 0.3 usage of ngImprovedTesting might be troublesome due to fact that the ModuleBuilder:
After quite a while I finally got round to creating version 0.2 of ngImprovedTesting.
ModuleBuilder API is unchanged and still makes mock testing AngularJS code much easier (be sure to read this blog post if you are unfamiliar with ngImprovedTesting).
Version 0.2 of ngImprovedTesting brings you the following interesting improvements:
- ngModuleIntrospector no longer uses internal AngularJS API.
- mocks can now also be created manually using the (global) “mockInstance” function.
- features a more descriptive way of testing promises by adding the
tick()method to $q.
- offers an module called “ngImprovedTesting” to be able to use $q.tick() in your tests without having to use the ModuleBuilder API (which automatically includes the module).
Being able to easily test your application is one of the most powerful features that AngularJS offers. All the services, controllers, filters even directives you develop can be fully (unit) tested.
However the learning curve for writing (proper) unit tests tends to be quite steep.
This is mainly because AngularJS doesn’t really offer any high level API’s to ease the unit testing. Instead you are forced to use the same (low level) services that AngularJS uses internally. That means you have to gain in dept knowledge about the internals of $controller, when to $digest and how to use $provide in order to mock these services. Especially mocking out a dependency of controller, filter or another service is too cumbersome.
This blog will show how you would normally create mocks in AngularJS, why its troublesome and finally introduces the new ngImprovedTesting library that makes mock testing much easier. Continue reading