0
votes

I want just run karma test inside a template called Clip-two.

when i start karma conf

karma start my.conf.js 

this is my error:

25 05 2017 11:36:10.911:WARN [karma]: No captured browser, open http://localhost:9876/ Chrome 49.0.2623 (Mac OS X 10.7.5) Users factory should exist FAILED Error: [$injector:modulerr] http://errors.angularjs.org/1.4.7/$injector/modulerr?p0=clip-two&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.7%2F%24injector%2Fmodulerr%3Fp0%3DngCookies%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.4.7%252F%2524injector%252Fnomod%253Fp0%253DngCookies%250A%2520%2520%2520%2520at%2520Error%2520(native)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Fbower_components%252Fangular%252Fangular.min.js%253Fb6b56d0e096efc26e09d6...cc346%3A41%3A35)%0A%20%20%20%20at%20Object.workFn%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fbower_components%2Fangular-mocks%2Fangular-mocks.js%3Fe9f36bdb59779aa33da5eab3dfd5ffda120d58aa%3A2427%3A52)

my karma confs is made by karma init command. I added all files only

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    angular: ['mocks'],

    // list of files / patterns to load in the browser
    files: [
      'bower_components/angular/angular.min.js',
      'bower_components/angular-animate/angular-animate.min.js',
      'bower_components/angular-touch/angular-touch.min.js',
      'bower_components/angular-sanitize/angular-sanitize.min.js',
      'bower_components/angular-ui-router/release/angular-ui-router.min.js',
      'bower_components/angular-mocks/angular-mocks.js',
      'bower_components/ngstorage/ngStorage.min.js',
      'bower_components/angular-translate/angular-translate.min.js',
      'bower_components/angular-translate-loader-url/angular-translate-loader-url.min.js',
      'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js',
      'bower_components/angular-translate-storage-local/angular-translate-storage-local.min.js',
      'bower_components/angular-translate-storage-cookie/angular-translate-storage-cookie.min.js',
      'bower_components/oclazyload/dist/ocLazyLoad.min.js',
      'bower_components/angular-breadcrumb/dist/angular-breadcrumb.min.js',
      'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
      'bower_components/angular-loading-bar/build/loading-bar.min.js',
      'bower_components/angular-scroll/angular-scroll.min.js',

      'STANDARD/assets/js/app.js',
      'STANDARD/assets/js/main.js',
      'STANDARD/assets/js/config.constant.js',
      'STANDARD/assets/js/config.router.js',
      'STANDARD/assets/js/services/agente.js',
      'STANDARD/assets/js/controllers/inboxCtrl.js',

      'STANDARD/assets/test/*.js'
    ],

    exclude: [
    ],
    preprocessors: {
    },

    reporters: ['progress'],
    port: 9876,

    colors: true,
    logLevel: config.LOG_WARN,

    autoWatch: true,
    browsers: ['Chrome'],

    singleRun: false,
    concurrency: Infinity
  })
}

this is my unit test

describe('Users factory', function() {

  // Before each test load our api.users module
  beforeEach(module('clip-two'));

  // Before each test set our injected Users factory (_Users_) to our local Users variable
  var $controller;

  beforeEach(angular.mock.inject(function(_$controller_){
    $controller = _$controller_;
  }));

  // A simple test to verify the Users factory exists
  it('should exist', function() {
    expect($controller).toBeDefined();
  });
});

and that my app.js

'use strict';
angular.module("clip-two", [
    'ngAnimate',
    'ngCookies',
    'ngStorage',
    'ngSanitize',
    'ngTouch',
    'ui.router',
    'ui.bootstrap',
    'oc.lazyLoad',
    'cfp.loadingBar',
    'ncy-angular-breadcrumb',
    'duScroll',
    'pascalprecht.translate',
]);

some advice?

2

2 Answers

1
votes

The error says that there is a problem with ngCookies in your test.

And when I look at your karma conf file, I can't see the file containing ngcookies loaded.

You probably just need to add it in karma.conf to make it work.

1
votes

Considering the error, it seems that when running karma, the host can't be reached. Can you access your application through http://localhost:9876/?

You may try to run them again keeping your browser opened on the above address, I know it seems that it doesn't make sense, but on some systems this fixes the issue.

Then taking a look at your karma file, maybe there are some dependencies missing. Be sure that you are including all the files you need, otherwise also when your tests will run, you may have few failures.

But I can understand that now the important is that tests run :D