Skip to main content
Tweeted twitter.com/#!/StackOverflowPT/status/451961995718574080
added 209 characters in body
Fonte Link
Silvio Andorinha
  • 8,6mil
  • 12
  • 56
  • 94

module.exports = function(config) { config.set({

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','requirejs'],


// list of files / patterns to load in the browser
files: [

  'app/bower_components/jquery/dist/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-cookies/angular-cookies.js', 
  'app/bower_components/angular-resource/angular-resource.js', 
  'app/bower_components/angular-sanitize/angular-sanitize.js', 
  'app/bower_components/angular-mocks/angular-mocks.js',      
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

  plugins: [
        'karma-junit-reporter',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-requirejs'
    ],    


// list of files to exclude
exclude: [
  
],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

reporters: ['dots'],


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

    browserNoActivityTimeout: 10000,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Firefox'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

}); }; `

O meu arquivo de teste:

describe('Controller: MainCtrl', function () {

// load the controller's module beforeEach(module('AbsenteismoApp'));

var MainCtrl, scope;

// Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl', { $scope: scope }); }));

it('deve verificar o tamanho do array expressao scope', function () { expect(scope.expressao.length).toBe(1); }); });

describe('Controller: MainCtrl', function () {

  // load the controller's module
  beforeEach(module('AbsenteismoApp'));

  var MainCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    MainCtrl = $controller('MainCtrl', {
      $scope: scope
    });
  }));

  it('deve verificar o tamanho do array expressao scope', function () {
    expect(scope.expressao.length).toBe(1);
  });
});
 'use strict';

angular.module('AbsenteismoApp') .controller('MainCtrl',['$scope',function($scope){


angular.module('AbsenteismoApp')
    .controller('MainCtrl',['$scope',function($scope){

        $scope.expressao = [];
  }]);

}]);

WARN [Firefox 27.0.0 (Windows 7)]: Disconnected (1 times), because no message in 10000 ms.

WARN [Firefox 27.0.0 (Windows 7)]: Disconnected (1 times), because no message in 10000 ms.

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','requirejs'],


// list of files / patterns to load in the browser
files: [

  'app/bower_components/jquery/dist/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-cookies/angular-cookies.js', 
  'app/bower_components/angular-resource/angular-resource.js', 
  'app/bower_components/angular-sanitize/angular-sanitize.js', 
  'app/bower_components/angular-mocks/angular-mocks.js',      
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

  plugins: [
        'karma-junit-reporter',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-requirejs'
    ],    


// list of files to exclude
exclude: [
  
],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

reporters: ['dots'],


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

browserNoActivityTimeout: 10000,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false

}); }; `

O meu arquivo de teste:

describe('Controller: MainCtrl', function () {

// load the controller's module beforeEach(module('AbsenteismoApp'));

var MainCtrl, scope;

// Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl', { $scope: scope }); }));

it('deve verificar o tamanho do array expressao scope', function () { expect(scope.expressao.length).toBe(1); }); });

'use strict';

angular.module('AbsenteismoApp') .controller('MainCtrl',['$scope',function($scope){

    $scope.expressao = [];

}]);

WARN [Firefox 27.0.0 (Windows 7)]: Disconnected (1 times), because no message in 10000 ms.

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','requirejs'],


// list of files / patterns to load in the browser
files: [

  'app/bower_components/jquery/dist/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-cookies/angular-cookies.js', 
  'app/bower_components/angular-resource/angular-resource.js', 
  'app/bower_components/angular-sanitize/angular-sanitize.js', 
  'app/bower_components/angular-mocks/angular-mocks.js',      
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

  plugins: [
        'karma-junit-reporter',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-requirejs'
    ],    


// list of files to exclude
exclude: [
  
],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

reporters: ['dots'],


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

    browserNoActivityTimeout: 10000,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Firefox'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

O meu arquivo de teste:

describe('Controller: MainCtrl', function () {

  // load the controller's module
  beforeEach(module('AbsenteismoApp'));

  var MainCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    MainCtrl = $controller('MainCtrl', {
      $scope: scope
    });
  }));

  it('deve verificar o tamanho do array expressao scope', function () {
    expect(scope.expressao.length).toBe(1);
  });
});
 'use strict';

angular.module('AbsenteismoApp')
    .controller('MainCtrl',['$scope',function($scope){

        $scope.expressao = [];
  }]);

WARN [Firefox 27.0.0 (Windows 7)]: Disconnected (1 times), because no message in 10000 ms.

Fonte Link

Resultados dos teste não aparecem no navegador - grunt-karma

Estou usando grunt e karma para fazer os testes do meu projeto. Mas quando uso o comando grunt test, os resultados não aparecem no navegador e nem na linda de comando.

A única coisa que aparece é o seguinte:

inserir a descrição da imagem aqui

Esse é o meu arquivo karma.conf.js:`// Karma configuration // Generated on Mon Mar 31 2014 10:21:42 GMT-0300 (E. South America Standard Time)

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','requirejs'],


// list of files / patterns to load in the browser
files: [

  'app/bower_components/jquery/dist/jquery.js',
  'app/bower_components/angular/angular.js',
  'app/bower_components/angular-cookies/angular-cookies.js', 
  'app/bower_components/angular-resource/angular-resource.js', 
  'app/bower_components/angular-sanitize/angular-sanitize.js', 
  'app/bower_components/angular-mocks/angular-mocks.js',      
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/spec/**/*.js'
],

  plugins: [
        'karma-junit-reporter',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-requirejs'
    ],    


// list of files to exclude
exclude: [
  
],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

reporters: ['dots'],


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

browserNoActivityTimeout: 10000,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false

}); }; `

O meu arquivo de teste:

describe('Controller: MainCtrl', function () {

// load the controller's module beforeEach(module('AbsenteismoApp'));

var MainCtrl, scope;

// Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl', { $scope: scope }); }));

it('deve verificar o tamanho do array expressao scope', function () { expect(scope.expressao.length).toBe(1); }); });

O que será testado:

'use strict';

angular.module('AbsenteismoApp') .controller('MainCtrl',['$scope',function($scope){

    $scope.expressao = [];

}]);

No prompt de comando aparece essa mensagem:

WARN [Firefox 27.0.0 (Windows 7)]: Disconnected (1 times), because no message in 10000 ms.