Angularjs 测试中的Karma指令
嗨,我正试图在业力测试中编译一个角度指令,如下所示:Angularjs 测试中的Karma指令,angularjs,karma-runner,Angularjs,Karma Runner,嗨,我正试图在业力测试中编译一个角度指令,如下所示: describe("Midway: Testing My App", function() { var $compile, $rootScope; beforeEach(module('KSSApp')); beforeEach(inject( ['$compile','$rootScope', function($c, $r) { $compile = $c; $ro
describe("Midway: Testing My App", function() {
var $compile, $rootScope;
beforeEach(module('KSSApp'));
beforeEach(inject(
['$compile','$rootScope', function($c, $r) {
$compile = $c;
$rootScope = $r;
}]
));
it("should compile the widget", function() {
var element = $c('<My-app></My-app>')($r);
console.log(element);
});
});
但是,这只是向元素添加了一个ng scope类,并没有编译完整的指令。您可能需要运行一个摘要循环,而且我认为您已经反转了注入和测试变量$scompile和$rootScope:
您可能需要运行摘要循环,而且我认为您已经反转了注入和测试变量$scompile和$rootScope:
此代码是正确的-KSSApp是否在其中定义了具有模板或templateUrl的指令?@EdhinchLiff是的,我的应用程序具有模板url。@EdhinchLiff,这是我希望它加载的位。好的,您是否使用预编译的javascript模板,或者它只是一个HTML文件?@EdHinchliffe只是模板文件的HTML。这段代码是正确的-KSSApp是否在其中定义了一个包含模板或模板url的指令?@EdHinchliffe是的,我的应用程序有一个模板url。@EdHinchliffe,这是我希望它加载的位。好的,您使用的是预编译的javascript模板,或者它只是一个HTML文件?@EdHinchliffe只是模板文件的HTML。
describe("Midway: Testing My App", function() {
var $compile, $rootScope;
beforeEach(module('KSSApp'));
beforeEach(inject(
['$compile','$rootScope', function($c, $r) {
$compile = $c;
$rootScope = $r;
}]
));
it("should compile the widget", function() {
// You're out of the inject function so I used full variable names
var element = $compile('<My-app></My-app>')($rootScope);
// run a digest loop
$rootScope.$digest();
console.log(element);
});
});