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:

  • didn't support service providers (like $stateProvider) that use the $rootElement (issue #11). This was caused by the fact that the internal ngModuleIntrospector didn't include the ngMock module.
  • didn't include the services from ngMock (i.e. $httpBackend) in the build module (issue #15).
  • didn't include the configuration of the original module in the build module (issue #11). To fix this issue the whole original module is included and afterwards the components specified using the ModuleBuilder will be re-registered in order have its dependencies mocked.
  • modules declared in .js files loaded afterwards the ModuleBuilder was build() couldn't previously be used by the ModuleBuilder (issue #9).
  • not all its ...WithMocksFor and ...WithMocksExcept methods properly support variable arguments for its toBeMockedDependencies / notToBeMockedDependencies argument (issue #16).
  • didn't correctly mock out dependencies of a service inherited from another module (issue #8).

Since the whole original module is now included in the build module:

  • the ...AsIs methods of the ModuleBuilder are no longer relevant and therefore are removed.
  • both the mocked service and its original service are now also part of the build module. To prevent the usage of the original service by mistake the (ngMock) inject function is enhanced to throw an exception when you are injecting a service for which a mock exists.

Furthermore the ModuleBuilder has been improved:

  • to allow specify more than 1 module name using the new static forModules method. The pre-existing forModule has been deprecated and will be removed in the future.
  • the new forModules besides a module name also supports providing a module configuration function and an object literal with service instance; just like angular.mock.module method.

With version 0.3 the core mocking functionality (mocking dependencies of a module component) of ModuleBuilder should now work as intended in all situations. In the future I'm planning on extending ngImprovedTesting:

  • to allow mocking out filters
  • to allow mocking regular controllers and controllers of a directive
  • with fluent api style fixtures for easily testing controllers and directives

Your feedback is more than welcome and much appreciated. So in case you have some ideas yourself on how to improved AngularJS testing, or stumbled upon a bug while using ngImprovedTesting, don't be shy and either comment on this blog post of file an issue (even to discuss ideas and features) on the GitHub repo

shadow-left