【发布时间】:2015-01-02 15:44:46
【问题描述】:
我正在使用 Jasmine Standalone 来测试我的 Angular 目录,
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' 不可用!你要么拼错了 模块名称或忘记加载它。如果注册一个模块,请确保 您将依赖项指定为第二个参数。
任何想法我错过了什么?
【问题讨论】:
标签: angularjs angularjs-directive jasmine