Angular 지시어 테스트에서 작동하도록 ng-repeat를 얻으 려하지만 $ scope 변수가 업데이트되고 $ digest()가 실행되면보기가 업데이트되지 않습니다. 호출됩니다.재시도 검사에서 Angular ng-repeat가 작동하지 않습니다
'use strict';
describe('Asset tests', function() {
var $compile,
$rootScope,
$scope,
$timeout,
templateHtml = '<span ng-repeat="asset in assets">{{asset.id}}</span>',
view;
beforeEach(function() {
module('my.module');
inject(function(_$compile_, _$rootScope_, _$timeout_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
$scope = $rootScope.$new();
$scope.assets = [];
$scope.selectedItems = [];
$scope.deleteAsset = function() {
console.log('yay');
};
view = angular.element(templateHtml);
$compile(view)($scope);
$scope.$apply();
});
});
describe('Testing some stuff', function() {
it('should test some stuff', function() {
for(var i = 0; i < 3; i ++) {
$scope.assets.push({id:i, name: 'Rad ' + i});
};
$scope.$digest();
console.log(view);
console.log(jQuery('span').length);
});
});
});
로그 문 출력 : HTML 템플릿을 제대로 컴파일하면
LOG: {0: <span ng-repeat="assets in assets">{{asset.id}}</span>, length: 1}
LOG: 56
그런 것들을 지적 해 주셔서 감사합니다. 여전히 같은 결과를 얻고 있습니다. 원본 코드 편집을 참조하십시오. – binarygiant