내 Angular 디렉토리를 테스트하기 위해 Jasmine Standalone을 사용하고 있습니다.
SimpleDirective.js
var app = angular.module("myApp", []);
app.controller('SimpleDirectiveController', function($scope) {
$scope.customer = {
name: 'Igor',
address: '123 Somewhere'
};
});
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: true,
// Isolate scope:
// separate the scope inside a directive from the scope outside, and then map the outer scope to a directive's inner scope.
scope: {
customerInfo: '=info'
},
//templateUrl points to an external html template.
templateUrl: 'fixture/hello.html'
};
});
fixture / hello.html,
<div class="customer"><b>Hello</b> {{customerInfo.name}}</div>
SimpleDirectiveSpec.js,
describe("simpleDirective Test ", function(){
// Boilerplate starts from here...
var compile, scope, element;
// Name of the module my directive is in.
beforeEach(module('myApp'));
// The external template file referenced by templateUrl.
beforeEach(module('fixture/hello.html'));
beforeEach(inject(function($compile,$rootScope) {
compile = $compile;
scope = $rootScope;
element = angular.element('<div data-hello-world info="customer"></div>');
compile(element)(scope);
scope.$digest();
}));
// ...Boilerplate ends here
it('renders the customer template', function() {
var customer = element.find('.customer');
expect(customer.length).toBe(1);
});
});
이 오류가 발생합니다.
오류 : [$ injector : modulerr] 다음으로 인해 모듈 fixture / hello.html을 인스턴스화하지 못했습니다. [$ injector : nomod] 모듈 'fixture / hello.html'을 사용할 수 없습니다! 모듈 이름을 잘못 입력했거나로드하는 것을 잊었습니다. 모듈을 등록하는 경우 종속성을 두 번째 인수로 지정해야합니다.
내가 놓친 아이디어가 있습니까?
템플릿에 대한 모듈을 만들고 템플릿 html을 templateCache에 넣어야합니다.
다음과 같이 표시되어야합니다.
angular.module("fixture/hello.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("fixture/hello.html",
"<div class=\"customer\"><b>Hello</b> {{customerInfo.name}}</div>");
}]);
Karma로 테스트하는 경우 ng-html2js 라는 이러한 목적을위한 자동화 karma 모듈이 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다