Post navigation

ngImprovedTesting 0.3: improved ModuleBuilder with lots of bug fixes

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:

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

About Emil van Galen

My name is Emil van Galen, I work for JDriven.
I'm passionate about software development and continuously seeking for ways to improve code, learn new technologies, improving software design and keeping things fresh.

Great to see that even after all this time people are still interested in ngImprovedTesting.
Although I didn’t make any changes to ngImprovedtesting for a while, it should be working in AngularJS version 1.2 up and until 1.5.

Personally I didn’t have any issues using it in 1.4.x.
Do you any particular issue?
Maybe Bower complains about that it expect AngularJS version 1.3.x? but that should be easy fixable by adding a resolution to your bower.json file

Just pushed changes to “ng-improved-testing-sample” GitHub repo so that it uses AngularJS 1.5 and the latest and greatest versions in its “package.json” and “bower.json”.

Let me know when you run against any issues.

Right now, ngImprovedTesting does not support the .component introduced in AngularJS 1.5 but adding it should be relatively easy to do.

Hopefully I will have some spare time the next few weeks to create a new release that add this feature as well as some other features / improvements like a more fine-grained way to enable / disable $q.tick() and support of using enabled $q.tick() support in combination with (a non mocked) $httpBackend.

Hoping to find some time next week to squeeze out a 0.4.0 beta release that would bring only one new feature:
AngularJS 1.5 .component support.

Other more time consuming new features and improvements will have to wait until I have some more time available, most likely after the nice summer weather ends ;-)
But before that time I might refactor the existing ngImprovedTesting.config API (since it might not be so much work) to support ignoring system services plus a more fine grained way to enable / disable $q.tick() support.