module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files/patterns to load in the browser
files: [
'../scripts/bower_components/angularjs/angular.js',
'../scripts/bower_components/angular-mocks/angular-mocks.js',
'../scripts/app.js',
'../scripts/11.js',
'../scripts/controllers/*.js',
'../scripts/directives/*.js',
'../scripts/services/*.js',
'controllers/controllersTests.js',
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS', 'PhantomJS_custom'],
customLaunchers: {
'PhantomJS_custom': {
base: 'PhantomJS',
options: {
windowName: 'my-window',
settings: {
webSecurityEnabled: false
},
},
flags: ['--load-images=true'],
debug: false
}
},
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
exitOnResourceError: true
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
我需要測試控制器的代碼,但我不能看到正確的結果,下面的代碼: 「滑動」陣列長度= 4 ;但在測試I寫 「砥(2)」 和我看到:
PhantomJS 1.9.8(Linux的0.0.0)○:執行0 ERROR(0.035秒/ 0秒)
爲什麼我看到0 0錯誤,如果我期望2,但數組長度是4?
app.controller('mainCtrl',['$scope', function($scope){
$scope.slide = [1, 2, 3, 4];
}]);
describe('Tests Controllers', function() {
beforeEach(module('app'));
var $controller;
beforeEach(inject(function(_$controller_, $rootScope){
$controller = _$controller_;
it('check slides length, it should be 4', function() {
var $scope = {};
var controller = $controller('mainCtrl', { $scope: $scope });
expect($scope.slide.length).toBe(2);
});
}));
});
您的測試文件甚至沒有執行,似乎是在安裝程序中的問題。這是你的第一個測試你的應用程序? Karma配置是否正確? –
是的,這是我的第一次測試。我已經附加了karma配置。 – trigger
你能分享你的Karma配置文件嗎? –