0

I have inherited two angular apps. The one app(AppB) that I'm writing tests for and for lack of better phrasing it sets atop another app(AppB) that I've created. I want each of these to be their own separate repos with tests that cover that repo.

So I have a module with a controller that I want to test that looks something like this

angular.module('moduleName', ['moduleDependency1','moduleDependency2','moduleDependency3'])

Where moduleDependency2 is not included in the config because this particular code doesn't need to be tested in this module.

I have tried setting the following up to test this module

beforeEach(function() {

    module('moduleName');

    inject(function (_$rootScope_, _$controller_, _$q_) {
        $rootScope = _$rootScope_;
        $scope = $rootScope.$new();
        $controller = _$controller_;
        $q = _$q_;
    });

});

however this returns:

Error: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=moduleName

I tried declaring each module dependency but the moduleDependency2 then threw an error about not being defined.

What am I missing here?

Chris Maness
  • 1,682
  • 3
  • 22
  • 40
  • If any of your code tries to call anything in `moduleDependency2` it's going to fail though. What you could do is create a polyfill/shim for `moduleDependency2` that you import instead for testing which has the same signature as the real module, but with fake methods etc. – Matti Price Jan 13 '17 at 19:15
  • 1
    Possible duplicate of [Mocking Angular module dependencies in Jasmine unit tests](http://stackoverflow.com/questions/17554727/mocking-angular-module-dependencies-in-jasmine-unit-tests) – Konstantin A. Magg Jan 13 '17 at 19:19

0 Answers0