您好,我正在用Jasmine编写我的第一个角度测试,但是我一直收到错误消息
这是我的控制器
(function () {
'use strict';
var dependencies = [];
angular.module('entityEdit', dependencies)
.config(configFn)
.run(runFn)
.directive('entityEdit', ['BASE_PATH', entityEditDirective])
.controller('EntityEditCtrl', ['$scope', '$rootScope','Entity', EntityEditCtrl])
function EntityEditCtrl($scope, $rootScope,Entity) {
$scope.entity = {};
$scope.list=[
{'id':"1",'libelle':'A' },
{'id':"2",'libelle':'B' },
]
$rootScope.$on('Entity_LIST_SELECTED', function (event, data) {
console.log("received");
$scope.entity = data;
});
$scope.save= saveFn;
function saveFn()
{
console.log("savefn");
console.log($scope.entity);
Entity.updateEntity($scope.entity);
}
}
function runFn() {
console.log('Run : entityEdit');
}
function configFn() {
console.log('Config : entityEdit');
}
})();
这是我的茉莉花测试
describe('EntityEditCtrl', function () {
var $rootScope, scope, $controller;
beforeEach(angular.mock.module('entityEdit'));
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
$controller('EntityEditCtrl', {
$scope: scope
});
ctrl = $controller('EntityEditCtrl',function(){});
}));
it('exists',inject(function($controller){
expect(ctrl).toBeDefined();
expect(ctrl).not.toBeNull();
expect(typeof ctrl).toBe('object');
}));
});
如果您发现问题,请告诉我
最佳答案
单元测试,如果您要测试特定的单元,则需要注入该单元内部所需的每个模块,此处缺少的模块就是实体。
describe('EntityEditCtrl', function () {
var $rootScope, scope, controller,Entity;
beforeEach(angular.mock.module(core.entity'));
beforeEach(angular.mock.module('entityEdit'));
beforeEach(inject(function ($rootScope, $controller,_Entity_) {
scope = $rootScope.$new();
Entity=_Entity_;
controller=$controller('EntityEditCtrl', {$scope: scope});
}));
it('exists',inject(function($controller){
expect(ctrl).toBeDefined();
expect(ctrl).not.toBeNull();
expect(typeof ctrl).toBe('object');
}));
});
关于angularjs - [$ injector:unpr未知提供者:GammeProvider <-Gamme <-GammeEditCtrl,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38815069/