Ошибка: [$ injector: unpr] Неизвестный поставщик: dataProvider <- data - PullRequest
0 голосов
/ 21 сентября 2018

Это мой код Js

(function () {
angular.module('app',[])
    .factory('code', function ($http, svc, $q) {
     function getCodeByID(id) {
            return $http.get(svc.get('my-application') + id)
                .then(function (res) {
                    return res;
                });
        }
    })
})();

Это мой файл Spec.js

 describe('MyController', function() {
var data, svc, code;
// Set up the module
//beforeEach(module('app'));
beforeEach(angular.mock.module('app'));
beforeEach(inject(function(_data_) {
    data = _data_;
}));
beforeEach(inject(function(_svc_) {
    svc = _svc_;
}));
beforeEach(inject(function(_code_) {
    code = _code_;
}));
it('Should exist', function() {
    expect(code).toBeDefined();
});});

Получение этой ошибки:

Error: [$injector:unpr] Unknown provider: dataProvider <- data
    https://errors.angularjs.org/1.7.4/$injector/unpr?p0=dataProvider%20%3C-%20data
        at node_modules/angular/angular.js:138:12
        at node_modules/angular/angular.js:4905:19
        at Object.getService [as get] (node_modules/angular/angular.js:5065:32)
        at node_modules/angular/angular.js:4910:45
        at getService (node_modules/angular/angular.js:5065:32)
        at injectionArgs (node_modules/angular/angular.js:5090:58)
        at Object.invoke (node_modules/angular/angular.js:5114:18)
        at UserContext.WorkFn (node_modules/angular-mocks/angular-mocks.js:3439:20)
    Error: Declaration Location
        at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:3402:25)
        at Suite.<anonymous> (src/app/epcCodes/epc.spec.js:9:16)
        at src/app/epcCodes/epc.spec.js:2:1

Я не знаю, почему я получаю эту ошибку, я добавил все внедрения зависимостей, которые необходимы для моего проекта.Можете ли вы дать мне решение для этого?

Ответы [ 3 ]

0 голосов
/ 01 октября 2018
angular.module('Svc', [])
.factory('Svc', function (Data, $injector, $http) {
    var ConfigData = Data;
    var Svc = {};
    Svc.get = function (key) {
        return ConfigData[key];
    };
    Svc.loadResourcePaths = function (resources) {
        resources.forEach(function (resource) {
            $http.get(Svc.get('security-api') + 'resources?name=' + resource)
                .then(function (response) {
                    if (response.data.totalElements === 1) {
                        ConfigData[resource] = response.data.content[0].href;
                    } else {
                    }
                })
        })
    };
    return Svc;
});
0 голосов
/ 01 октября 2018
(function () {
angular
    .module('app', [
        'ConfigSvc',
        'AuthUtils',
        'ngCsv'
    ])

    .constant('APPNAME', 'ui')
    .constant('APPLABEL', 'app_label')
    .constant('APPPREFIX', 'App_name')

    .config(function ($mdThemingProvider) {
        $mdThemingProvider.theme('default')
            .primaryPalette('grey', {'default': '900'})
            .accentPalette('blue', {'default': '400'})
        ;
    })
    .config(function routesConfig($stateProvider, $urlRouterProvider, $locationProvider, $mdAriaProvider) {
        $locationProvider.html5Mode(true).hashPrefix('!');
        $urlRouterProvider.otherwise('/');
        $stateProvider
            .state('home', {
                url: '/',
                template: '<app></app>',
                data: {
                    label: 'Home',
                    icon: 'home',
                    menu: true
                }
            });
    });


angular.element(document).ready(function () {

    var initInjector = angular.injector(['ng']);
    var $http = initInjector.get('$http');

    $http.get('appConfig.json')
        .then(function (response) {
            angular.module('app').constant('Data', response.data);

            return $http.get('appFeatures.json')
        })
        .then(function (response) {

            angular.module('app').constant('ccAppFeatures', response.data);
        })
        .finally(function () {

            angular.bootstrap(document, ['app']);
        });
});})();
0 голосов
/ 22 сентября 2018
  1. Вам нужен только один из этих beforeEach блоков, в которые вы вводите свои услуги - хотя это не имеет никакого отношения к вашей проблеме.

  2. Этоодна из них связана с вашей проблемой - вы «говорите» своему тесту внедрить data компонент / сервис / фабрику, когда такой код явно не существует в вашем коде.Что вы ожидаете от data?

...