evangalen / ng-improved-testing

Improves AngularJS testing
MIT License
21 stars 4 forks source link

MockBuilder doesn't correctly handle components declared in inherited modules #8

Closed evangalen closed 9 years ago

evangalen commented 9 years ago

The ModuleBuilder currently correctlty handle components declared in inherited modules. Consider the following module:

angular.module('aModule', [])
    .factory('mockableService', function() {
        return {
            aMethod: function() { /* ... */ }
        };
    })
    .factory('serviceUsingMockableService', function(mockableService) {
        return {
            anotherMethod: function() {
            /* ... */
        }
        };
    });

The ModuleBuilder with succesfully include "serviceUsingMockableService" with a mocked-out "mockableService":

ModuleBuilder.forModule('aModule')
    .serviceWithMocks('serviceUsingMockableService')
    .build();

But the ModuleBuilder won't work when you would use 'aModule' as an inherited module from another module:

angular.module('anotherModule', [])

When doing a "forModule" on "anotherModule" the original "serviceUsingMockableService" (without mocks) will be returned (and MockBuilder therefor acts unexpectedly):

ModuleBuilder.forModule('anotherModule')
    .serviceWithMocks('serviceUsingMockableService')
    .build();
evangalen commented 9 years ago

Fixed in the (upcoming) 0.3.0 version.