Édouard Lopez
Édouard Lopez

Reputation: 43401

Unit testing Module with with $routeParams fails?

I'm already using test case where I use $routeParams without a glicth but I can't make it work on this new test case.

Module

I reduce its content to the minimal

"use strict";

angular.module('warehousesModule', ['smart-table', 'services', 'ngRoute'])
.controller('WarehouseEditCtrl', [
    '$scope', '$routeParams', '$location', '$window', 'API', 'gettextCatalog', 'form',
    function ($scope, $routeParams, $location, $window, API, gettextCatalog, form) {
}]);

Unit test

"use strict";

describe('testModule', function () {
    beforeEach(module('warehousesModule'));

    describe('WarehouseEditCtrl', function () {
        var $scope, ctrl, $httpBackend;

        beforeEach(inject(function ($rootScope, $routeParams, $controller) {
            $routeParams.compoundId = 3;
            $scope = $rootScope.$new();
            ctrl = $controller('WarehouseEditCtrl', {
                $scope: $scope
            });
        }));

        it('dummy', function () {
        });
    });
});

If I change the module and controller to another one (e.g. productsModule), it run without error.

Error message

Error: [$injector:unpr] Unknown provider: $routeParamsProvider <- $routeParams
http://errors.angularjs.org/1.3.15/$injector/unpr?p0=%24routeParamsProvider%20%3C-%20%24routeParams
    at /home/elopez/projects/tcs_economat/frontend/static/js/vendor.min.js:1
    at r (/home/elopez/projects/tcs_economat/frontend/static/js/vendor.min.js:1)
    at /home/elopez/projects/tcs_economat/frontend/static/js/vendor.min.js:1
    at r (/home/elopez/projects/tcs_economat/frontend/static/js/vendor.min.js:1)
    at i (/home/elopez/projects/tcs_economat/frontend/static/js/vendor.min.js:1)
    at workFn (/home/elopez/projects/tcs_economat/frontend/static_src/bower_components/angular-mocks/angular-mocks.js:2436)
undefined

Question

Both modules are in my main app, do you see what's the problem here ?

Upvotes: 0

Views: 477

Answers (1)

&#201;douard Lopez
&#201;douard Lopez

Reputation: 43401

Solution

I find the solution by reviewing my code with a colleague, so peer-review is the solution here !

  1. I was missing the ngRoute dependency in my module ;
angular.module('warehousesModule', ['smart-table', 'services', 'ngRoute'])
  1. I forget to rebuild my *.min.js after adding the dependency.
gulp default

Upvotes: 1

Related Questions