我需要为AngularJS编写一个自定义模块,但是我找不到关于这个主题的任何好的文档.如何为AngularJS编写可以与他人共享的自定义模块?
继续给我这个错误:模块"模板"不可用!您要么错误拼写了模块名称,要么忘记加载它.
我在几个Angular项目中实现了Directives的单元测试,现在它似乎无法工作.这是我的karma.conf
module.exports = function(config){
config.set({
basePath : '../',
files : [
'webapp/lib/bower_components/angular/angular.js',
'webapp/lib/bower_components/angular-route/angular-route.js',
'webapp/lib/bower_components/angular-resource/angular-resource.js',
'webapp/lib/bower_components/angular-animate/angular-animate.js',
'webapp/lib/bower_components/angular-mocks/angular-mocks.js',
'webapp/lib/bower_components/jquery/jquery.js',
'webapp/lib/jasmine-jquery.js',
'webapp/js/components/**/*.html',
'webapp/app.js',
'webapp/js/**/*.js',
'test/unit/**/*.js',
{ pattern: 'webapp/stubs/*', watched: true, served: true, included: false }
],
preprocessors: {
'webapp/js/components/**/*.html': ['ng-html2js']
//'webapp/components/**/.js' : ['coverage']
},
autoWatch : true,
frameworks: ['jasmine'],
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
},
ngHtm2JsPreprocessor: {
moduleName: 'templates'
}
});
};
Run Code Online (Sandbox Code Playgroud)
我绝对100%肯定在给定位置有.html文件.我仔细检查了说明,它只是不会加载:beforeEach(module('templates'));在spec文件中.
我在这里错过了什么吗?最可能 :-)
--edit:在'webapp/js/components/**/*.html'路径中忘了'js',仍然无法正常工作.
whenGET不是一个函数,但是当我输出proxyvar我时,看到函数就在那里
{ when: [Function],
whenGET: [Function],
whenPUT: [Function],
whenHEAD: [Function],
whenPOST: [Function],
whenDELETE: [Function],
whenPATCH: [Function],
whenJSONP: [Function],
context: {},
flush: [Function],
syncContext: [Function],
onLoad: [Getter]
}
Run Code Online (Sandbox Code Playgroud)
规范
describe('Login', function () {
var Injector = require('./helpers/injector');
var loginPage = require('./pageObjects/LoginPage.js');
var HttpBackend = require('http-backend-proxy');
var proxy = new HttpBackend(browser);
var loginJsonStub,
loginPost,
URLbase;
//projectsJsonStub;
beforeEach(function () {
browser.get('http://localhost:9001/#');
loginPost = {'Login': 'sjv', 'Password': 'password'};
var injector = new Injector();
injector.get('loginJson').then(function (result) {
loginJsonStub = result;
});
var injector …Run Code Online (Sandbox Code Playgroud)