gpt4 book ai didi

angularjs - [$注入(inject)器:unpr Unknown provider: GammeProvider <- Gamme <- GammeEditCtrl

转载 作者:行者123 更新时间:2023-12-03 06:49:32 25 4
gpt4 key购买 nike

您好,我正在用 Jasmine 编写我的第一个 Angular 测试,但我不断收到错误这是我的 Controller

(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');
}
})();

这是我的 Jasmine 测试

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');
}));
});

如果您发现问题,请告诉我

最佳答案

单元测试,如果您想测试特定单元,您需要注入(inject)该单元内所需的每个模块,而这里缺少的模块是实体。

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 - [$注入(inject)器:unpr Unknown provider: GammeProvider <- Gamme <- GammeEditCtrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38815069/

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