gpt4 book ai didi

javascript - 未知提供者 : ngDialogProvider

转载 作者:行者123 更新时间:2023-11-29 20:54:44 25 4
gpt4 key购买 nike

我一直在名为 PatientCommonController 的 Controller 中使用 ngDialog,它一直按预期完美运行。
当我运行“grunt test”来测试我的代码时,问题就出现了。在 stackoverflow 上搜索解决方案时,我尝试了此修复:"Unknown provider: ngDialogProvider"

我没有成功。我做错了什么?

Error: [$injector:unpr] Unknown provider: ngDialogProvider <- ngDialog <- PatientCommonController
http://errors.angularjs.org/1.4.9/$injector/unpr?p0=ngDialogProvider%20%3C-%20ngDialog%20%3C-%20PatientCommonController in /home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js (line 68)
minErr/<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:68:12
createInjector/providerCache.$injector<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4346:19
getService@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4494:39
createInjector/instanceCache.$injector<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4351:28
getService@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4494:39
invoke@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4526:13
instantiate@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4543:27
$ControllerProvider/this.$get</<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:9395:18
angular.mock.$ControllerDecorator</<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular-mocks/angular-mocks.js:1960:12
@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/test/unit/registration/controllers/patientCommonController.spec.js:40:9

Error: [$injector:unpr] Unknown provider: ngDialogProvider <- ngDialog <- PatientCommonController <- PatientCommonController
http://errors.angularjs.org/1.4.9/$injector/unpr?p0=ngDialogProvider%20%3C-%20ngDialog%20%3C-%20PatientCommonController%20%3C-%20PatientCommonController in /home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js (line 68)
minErr/<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:68:12
createInjector/providerCache.$injector<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4346:19
getService@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4494:39
createInjector/instanceCache.$injector<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4351:28
getService@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4494:39
invoke@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4526:13
instantiate@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:4543:27
$ControllerProvider/this.$get</<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular/angular.js:9395:18
angular.mock.$ControllerDecorator</<@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/app/components/angular-mocks/angular-mocks.js:1960:12
createController@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/test/unit/registration/controllers/patientCommonController.spec.js:182:13
@/home/krishnanspace/Projects_2/bahmni/openmrs-module-bahmniapps/ui/test/unit/registration/controllers/patientCommonController.spec.js:289:13

编辑 1:我的测试文件

'use strict';

describe('PatientCommonController', function () {

var $aController, $httpBackend, scope, appService, rootScope,  patientAttributeService;
var spinner = jasmine.createSpyObj('spinner', ['forPromise']);

beforeEach(module('bahmni.registration'));

beforeEach(module(function ($provide) {
$provide.value('patientAttributeService', {});
}));

beforeEach(
inject(function ($controller, _$httpBackend_, $rootScope) {
$aController = $controller;
$httpBackend = _$httpBackend_;
scope = $rootScope.$new();
rootScope = $rootScope;
})
);


beforeEach(function () {
appService = jasmine.createSpyObj('appService', ['getAppDescriptor']);

rootScope.genderMap = {};

scope.patient = {};

appService.getAppDescriptor = function () {
return {
getConfigValue: function (config) {
return true;
}

};
};

$aController('PatientCommonController', {
$scope: scope,
$rootScope: rootScope,
appService: appService
});

$httpBackend.whenGET(Bahmni.Common.Constants.globalPropertyUrl + '?property=concept.reasonForDeath').respond({});
$httpBackend.when('GET', Bahmni.Common.Constants.conceptUrl).respond({});
$httpBackend.flush();

});


it("should make calls for reason for death global property and concept sets", function () {
$httpBackend.expectGET(Bahmni.Common.Constants.globalPropertyUrl);
$httpBackend.expectGET(Bahmni.Common.Constants.conceptUrl);
});

it("should show caste same as last name if the configuration is set to true", function () {

rootScope.patientConfiguration = {attributeTypes: [{name: 'Caste'}, {name: 'Class'}]};

expect(scope.showCasteSameAsLastName()).toBeTruthy();
});

it("should show caste same as last name if the configuration is set to true irrespective of patient attribute case sensitivity", function () {
rootScope.patientConfiguration = {attributeTypes: [{name: 'caSTe'}, {name: 'Class'}]};

expect(scope.showCasteSameAsLastName()).toBeTruthy();
});

it("should not show caste same as last name if the configuration is set to true, but person attribute caste is not there", function () {
rootScope.patientConfiguration = {attributeTypes: [{name: 'Class'}]};

expect(scope.showCasteSameAsLastName()).toBeFalsy();
});

it("showBirthTime should be true by default", function () {
expect(scope.showBirthTime).toBe(true);
});

it("showBirthTime should be false if set false", function () {

appService.getAppDescriptor = function () {
return {
getConfigValue: function (config) {
if (config == "showBirthTime") {
return false;
}
}
};
};

$aController('PatientCommonController', {
$scope: scope,
$rootScope: rootScope,
http: $httpBackend,
patientAttributeService: patientAttributeService,
spinner: spinner,
appService: appService
});
expect(scope.showBirthTime).toBe(false);
});

describe("show or hide sections", function () {
var sections;
var createController = function () {
appService = jasmine.createSpyObj('appService', ['getAppDescriptor']);

rootScope.genderMap = {};

scope.patientLoaded = true;
var showOrHideSection = function (patient) {
var returnValues = {
show: [],
hide: []
};
if (patient["age"].years < 18) {
returnValues.show.push("additionalPatientInformation")
} else {
returnValues.hide.push("additionalPatientInformation")
}
return returnValues
};

var showOrHideSectionOfCareTaker = function (patient) {
var returnValues = {
show: [],
hide: []
};
if (patient["legalRepAlsoCaretaker"] && patient["legalRepAlsoCaretaker"].value.fullySpecifiedName === "Yes") {
returnValues.show.push("caretaker");
} else {
returnValues.hide.push("caretaker");
}
return returnValues
}
Bahmni.Registration.AttributesConditions.rules = {
'age': function (patient) {
return showOrHideSection(patient);
},

'birthdate': function (patient) {
return showOrHideSection(patient);
},
'legalRepAlsoCaretaker': function (patient) {
return showOrHideSectionOfCareTaker(patient);
}
};

sections = {
"additionalPatientInformation": {
attributes: [{
name: "education"
}, {
foo: "bar"
}]
},
"caretaker": {
attributes: [{
name: "something"
}, {
foo: "bar"
}]
}
};

rootScope.patientConfiguration = {
getPatientAttributesSections: function () {
return sections;
}
};

appService.getAppDescriptor = function () {
return {
getConfigValue: function (config) {
return true;
}

};
};

$aController('PatientCommonController', {
$scope: scope,
$rootScope: rootScope,
appService: appService
});

$httpBackend.whenGET(Bahmni.Common.Constants.globalPropertyUrl + '?property=concept.reasonForDeath').respond({});
$httpBackend.when('GET', Bahmni.Common.Constants.conceptUrl).respond({});
$httpBackend.flush();

};
it("should show additional attributes section if age is less than 18 on page load", function () {
scope.patient = {
'age': {
years: 10
}
};

createController();
expect(sections.additionalPatientInformation.canShow).toBeTruthy();
});

it("should hide additional attributes section if age is greater than 18 on page load", function () {

scope.patient = {
'age': {
years: 20
}
};

createController();
expect(sections.additionalPatientInformation.canShow).toBeFalsy();
});

it("should hide caretaker attributes section if legalRepAlsoCaretaker is selected as 'No'", function () {
scope.patient = {
'age': {
years: 20
},
'legalRepAlsoCaretaker': {
'value': {
fullySpecifiedName: "No"
}
}
};

createController();
expect(sections.caretaker.canShow).toBeFalsy();
});

it("should hide caretaker attributes section on page load", function () {
scope.patient = {
'age': {
years: 20
}
}

createController();
expect(sections.caretaker.canShow).toBeFalsy();
});

it("should show or hide caretaker attributes section if legalRepAlsoCaretaker value changes ", function () {

scope.patient = {
'age': {
years: 20
}
};

createController();
expect(sections.caretaker.canShow).toBeFalsy();

scope.patient = {
'age': {
years: 20
},
'legalRepAlsoCaretaker': {
'value': {
fullySpecifiedName: "Yes"
}
}
};
scope.handleUpdate('legalRepAlsoCaretaker');
expect(sections.caretaker.canShow).toBeTruthy();

scope.patient = {
'age': {
years: 20
},
'legalRepAlsoCaretaker': {
'value': {
fullySpecifiedName: "No"
}
}
};
scope.handleUpdate('legalRepAlsoCaretaker');
expect(sections.caretaker.canShow).toBeFalsy();

});
it("should hide additional attributes section if age is greater than 18 on value change", function () {

scope.patient = {
'age': {
years: 10
}
};

createController();
expect(sections.additionalPatientInformation.canShow).toBeTruthy();

scope.patient = {
'age': {
years: 20
}
};
scope.handleUpdate('age');
expect(sections.additionalPatientInformation.canShow).toBeFalsy();

scope.patient = {
'age': {
years: 8
}
};
scope.handleUpdate('age');
expect(sections.additionalPatientInformation.canShow).toBeTruthy();
})
})})

最佳答案

大多数时候人们得到​​这个错误是因为他们没有包含模块:

beforeEach(module('ngDialogProvider'));

请查看:Getting Unknown Provider error when injecting a Service into an Angular unit test

关于javascript - 未知提供者 : ngDialogProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49891944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com