我正在使用Qunit frameword为ng-grid编写单元测试。这是我的实施:
module("Test grid angular", {
setup: function(){
injectorGrid = angular.injector(["ng", "ngGrid"]);
$scope = injectorGrid.get('$rootScope').$new();
$scope.currentPortfolioList = [
{
'symbol': 'bbb',
'available': 100,
'mortage' : 0
},
{
'symbol': 'AAA',
'available': 0,
'mortage' : 1000
}];
$scope.gridTest = {
data: 'currentPortfolioList',
enableCellSelection: false,
enableCellEditOnFocus: true,
multiSelect: false,
columnDefs: [
{field: 'symbol', displayName: 'Ma'},
{field: 'available', displayName: 'KL GD'},
{field: 'mortage', displayName: 'KL CC'}
]
};
},
teardown: function(){
$("#gridview").html("");
}
});
test('hide column', function(){
$scope.gridTest.columnDefs[0].visible = false;
var el = '<div ng-grid="gridTest"></div>';
var $compile = injectorGrid.get('$compile');
var element = $compile(el)($scope);
$("#gridview").html(element);
$scope.$digest();
var col0 = element.find(".col0");
ok(col0.length == 0);
});
module("Test grid angular", {
setup: function(){
injectorGrid = angular.injector(["ng", "ngGrid"]);
$scope = injectorGrid.get('$rootScope').$new();
$scope.currentPortfolioList = [
{
'symbol': 'bbb',
'available': 100,
'mortage' : 0
},
{
'symbol': 'AAA',
'available': 0,
'mortage' : 1000
}];
$scope.gridTest = {
data: 'currentPortfolioList',
enableCellSelection: false,
enableCellEditOnFocus: true,
multiSelect: false,
columnDefs: [
{field: 'symbol', displayName: 'Ma'},
{field: 'available', displayName: 'KL GD'},
{field: 'mortage', displayName: 'KL CC'}
]
};
},
teardown: function(){
$("#gridview").html("");
}
});
test('hide column', function(){
$scope.gridTest.columnDefs[0].visible = false;
var el = '<div ng-grid="gridTest"></div>';
var $compile = injectorGrid.get('$compile');
var element = $compile(el)($scope);
$("#gridview").html(element);
$scope.$digest();
var col0 = element.find(".col0");
ok(col0.length == 0);
});
虽然我的测试用例已通过,但我在Firefox浏览器的控制台日志中看到一条错误消息,如下所示:
[$ compile:ctreq] http://errors.angularjs.org/1.2.16/ $ compile / ctreq?p0 = ngInclude&amp; p1 = ngInclude
\&lt; \ div class =“ngHeaderScroller”ng-style =“headerScrollerStyle()”ng-include =“gridId”'headerRowTemplate.html'“
我发现调用时发生了这个错误:$ compile(el)($ scope);
你能帮我解决一下这个问题吗?
答案 0 :(得分:1)
使用Batarang查看有问题的nginclude
指令:
gridId' 'headerRowTemplate.html'
不是有效的参考。
当HTML编译器尝试处理指令定义中指定require选项的指令时,会发生此错误,但当前DOM元素(或其祖先元素,如果指定了^)上不存在所需的指令控制器。 / p>
要解决此错误,请确保所需控制器名称中没有拼写错误,并且当前元素上存在所需的指令控制器。
<强>参考强>