programing

Carma Jasmine 테스트 실행에서 각도 모듈을 사용할 수

elecom 2023. 10. 5. 21:12
반응형

Carma Jasmine 테스트 실행에서 각도 모듈을 사용할 수

개발을 위해 각진 풀스택을 사용하고 있습니다. karma.conf.js 파일은

files: [             
    'app/bower_components/jquery/jquery.js',
    'app/bower_components/angular/angular.js',
    'app/bower_components/angular-mocks/angular-mocks.js',
    'app/bower_components/angular-cookies/angular-cookies.js',
    'app/bower_components/angular-resource/angular-resource.js',
    'app/bower_components/angular-route/angular-route.js',
    'app/bower_components/angular-sanitize/angular-sanitize.js',
    'app/bower_components/angular-scenario/angular-scenario.js',
    'app/scripts/controllers/*.js',
    'app/scripts/directives/*.js',
    'app/scripts/services/*.js',
    'app/scripts/app.js',
    'lib/routes.js',           
    'test/karma/unit/**/test.spec.js'      
],

테스트 규격:

'use strict';

(function() {
describe('App', function() {

    describe('TestController', function() {

        beforeEach(function() {
            this.addMatchers({
                toEqualData: function(expected) {
                    return angular.equals(this.actual, expected);
                }
            });
        });

        // Load the controllers module
        beforeEach(module('ratefastApp'));

        // Initialize the controller and a mock scope
        var TestController,
            mockUserResource,
            scope,
            $httpBackend,
            $routeParams,
            $location;

        // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
        // This allows us to inject a service but then attach it to a variable
        // with the same name as the service.

        beforeEach(
            inject(function($controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_) {
            scope = $rootScope.$new();
            TestController = $controller('TestController', {
                $scope: scope
            });
            $routeParams = _$routeParams_;
            $httpBackend = _$httpBackend_;
            $httpBackend.when('GET', '/api/test/page/:pagenum')
                .respond([{title: 'test'}]);
            $location = _$location_;

        }));
    });
});
});

위의 내용을 실행할 때마다$injector:nomod Module is not available.

애플리케이션의 나머지 부분 전에 모듈을 업보 파일에 로드해야 합니다.

모듈이 아직 정의되지 않은 상태에서 종속성 배열 없이 angular. module를 호출하면 이 오류가 발생하기 때문입니다. docs.angularjs.org따라서 나머지 응용프로그램 이전에 파일을 명시적으로 로드해야 합니다.

카르마.config javascript 파일에서:

    'app/bower_components/jquery/jquery.js',
    'app/bower_components/angular/angular.js',
    'app/bower_components/angular-mocks/angular-mocks.js',
    'app/bower_components/angular-cookies/angular-cookies.js',
    'app/bower_components/angular-resource/angular-resource.js',
    'app/bower_components/angular-route/angular-route.js',
    'app/bower_components/angular-sanitize/angular-sanitize.js',
    'app/bower_components/angular-scenario/angular-scenario.js',

    'app/scripts/app.js',        // Load your module before the rest of your app.

    'app/scripts/controllers/*.js',
    'app/scripts/directives/*.js',
    'app/scripts/services/*.js',
    'lib/routes.js',           
    'test/karma/unit/**/test.spec.js' 

이 오류는 일부 모듈을 찾을 수 없음을 나타냅니다.특히 loader.js의 소스는 모듈을 등록하지 않았을 때 이 오류가 발생함을 보여주는 것 같습니다.angular.module. 당신은 그렇게 했습니까?ratefastApp? 복사된 소스는 다음과 같습니다.

    if (!requires) {
      throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
         "the module name or forgot to load it. If registering a module ensure that you " +
         "specify the dependencies as the second argument.", name);
    }  

그리고 주사를 놓으려고 하니까.$controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_, 가짜 $inject를 사용해서, 우선 카르마.conf.js에 있는 서비스를 포함한 파일을 확인하는 것부터 시작하겠습니다.files지시의와일드카드를 사용하여 모든 각도 파일을 포함할 수도 있습니다.

언급URL : https://stackoverflow.com/questions/21700615/angular-module-not-available-in-karma-jasmine-test-run

반응형