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
})
}
Мне нужно проверить код контроллеров, но я не вижу правильного результата, код ниже: "slide" array length = 4; но в тесте я пишу "toBe (2)", и я вижу:
PhantomJS 1.9.8 (Linux 0.0.0): Выполнено 0 из 0 ОШИБКА (0,035 сек /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 не может найти ваши тесты и отображает Executed 0 of 0 ERROR
, самыми популярными причинами, которые приводят к такому поведению, являются:
karma.conf.js
files:[]
it
блокирует) в тестовом файле/папке, поэтому Карме нечего делать. Это может произойти также, если спецификации помещены неправильно в тестовый файл, например, в вашем случае вы поместили it
внутри beforeEach
, но Jasmine его не поддерживает. Идея состоит в том, чтобы поставить их на один уровень. it
SPEC может жить отдельно в глобальном масштабе или прямо в describe
люкса блоков.