有人可以幫我這個問題:AngularJS測試及部件
角項目:
gui_service /客戶/ src目錄/ JS/remoteGuiApp.js:
angular.module('remoteGuiApp', ['ui.bootstrap', 'ngRoute', 'ngSanitize', 'ngResource'])
gui_service/client/src/modules/login/login.js
angular.module('remoteGuiApp')
.component('login', {
controller: function() {
this.login = '';
this.password = '';
this.showError = false;
},
templateUrl: '/src/modules/login/login.html'
});
此外,我還爲此組件提供了'/src/modules/login/login.html'模板。
gui_service /客戶/測試/ karma.conf
module.exports = function (config) {
'use strict';
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
'../src/vendor/js/angular.min.js',
'../src/vendor/js/angular-mocks.js',
'../src/vendor/js/angular-route.min.js',
'../src/vendor/js/angular-resource.min.js',
'../src/vendor/js/angular-sanitize.min.js',
'../src/vendor/js/angular-cookies.min.js',
//Library Files
'../src/vendor/js/jquery-2.2.4.min.js',
'../src/vendor/js/moment.js',
'../src/vendor/js/bootstrap.min.js',
'../src/vendor/js/ui-bootstrap.js',
'../src/js/remoteGuiApp.js',
'../src/js/Authentication.js',
'../src/modules/login/login.js',
//tests
'*.js',
//templates
'../src/modules/**/*.html'
],
// generate js files from html templates
preprocessors: {
'../src/modules/**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'client/'
},
reporters: ['mocha'],
port: 9876,
colors: true,
autoWatch: true,
singleRun: false,
// level of logging
logLevel: config.LOG_INFO,
browsers: ['Chrome'],
concurrency: Infinity
});
};
最後我的問題點: gui_service /客戶/測試/ LoginComponent-test.js:
describe('Component: login', function() {
beforeEach(module('remoteGuiApp'));
// load the login template
beforeEach(module('/src/modules/login/login.html'));
let scope;
let element;
let controller;
beforeEach(inject(function($rootScope, $compile) {
element = angular.element('<login></login>');
scope = $rootScope.$new();
$compile(element)(scope);
scope.$digest();
}));
it('Controller fields', function(done) {
expect(true).true;
done();
});
});
由於發射業力的結果我有這樣的錯誤:angular link error
也許有人會告訴解決這個問題。謝謝你的幫助。
爲什麼你要在'module(...)'中傳遞一個HTML文件路徑? – tanmay
,因爲我使用karma-ng-html2js-preprocessor – Sergaros
我對此沒有太多的想法,但看着你的角度鏈接錯誤,這似乎是這裏的罪魁禍首.. – tanmay