jeudi 26 novembre 2015

AngularJS karma jasmine test can't find route provider

I have angular script post.js and test for it post_test.js.

my post.js file

var Post = angular.module('Post', []);

Post
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/post', {
                controller: 'PostCtrl',
                templateUrl: 'src/posts/partials/post.html'
            })
        ;
    }]);

and my post_test.js file:

'use strict';

describe('Post module', function() {

    beforeEach(module('Post'));

    describe('Post controller', function(){

        it('should ....', inject(function($controller) {
            //spec body
            var PostCtrl = $controller('PostCtrl');
            expect(PostCtrl).toBeDefined();
        }));

    });
});

in karma.conf.js I load

files: [
    'app/components/angular/angular.js',
    'app/components/angular-route/angular-route.js',
    'app/components/angular-mocks/angular-mocks.js',
    'app/app.js',
    'app/src/**/*.js' // post.js, post_test.js
],

Everything seems OK, but angular returns this error:

Error: [$injector:modulerr] Failed to instantiate module Post due to:
Error: [$injector:unpr] Unknown provider: $routeProvider

I don't know why. I load angular-route.js before post.js. I've checked and it loads correctly. I've put alert(1) before defining $routeProvier and I've seen it in console. So this file is loading correctly, but in next file - test file it still doesn't work.

Aucun commentaire:

Enregistrer un commentaire