测试指令时,我得到 typeerror compile is not a function
when testing a directive, I get typeerror compile is not a function
当我尝试测试我的指令时,我得到了 TypeError: compile is not a function。
这是我的测试用例:
describe('directive tests', function () {
var element, $compile, scope;
beforeEach(module('App'));
beforeEach(inject(function (_$compile_, $rootScope) {
$compile = _$compile_;
scope = $rootScope.$new();
}));
it('should be Hello', function () {
element = $compile('<div Hello></div>')(scope);
...
});
});
如果我注释定义模块的行 (beforeEach(modue('App')),编译工作正常,但我无法引用我的指令。
在 karma.conf.js 中,添加包含对应用程序模块的引用的文件
files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],
当我尝试测试我的指令时,我得到了 TypeError: compile is not a function。 这是我的测试用例:
describe('directive tests', function () {
var element, $compile, scope;
beforeEach(module('App'));
beforeEach(inject(function (_$compile_, $rootScope) {
$compile = _$compile_;
scope = $rootScope.$new();
}));
it('should be Hello', function () {
element = $compile('<div Hello></div>')(scope);
...
});
});
如果我注释定义模块的行 (beforeEach(modue('App')),编译工作正常,但我无法引用我的指令。
在 karma.conf.js 中,添加包含对应用程序模块的引用的文件
files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],