1

i m using karma-mocha ..my karma.conf file is working with karma-jasmine...but not working with karma-mocha....my karma.conf file:--

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

    basePath : '../app',

    preprocessors: {
      '**/*.html':'ng-html2js'
    },

    ngHtml2JsPreprocessor: {
      prependPrefix: '/'
    },

    files : [
    'node_modules/jquery/**/*.js',
      'lib/angular/angular.js',
      'lib/angular/angular-*.js',
      '../test/lib/angular-mocks.js',
      '../test/lib/sinon-1.15.0.js',
      '../test/chai/chai.js',
      'js/**/*.js',
      '../test/unit/**/*.js',
      '**/*.html'
    ],

    autoWatch : true,

    frameworks: ['mocha','requirejs','chai'],

    browsers : ['Chrome'],

    plugins : [
      'karma-chrome-launcher',
      'karma-mocha',
      'karma-ng-html2js-preprocessor',
      'karma-requirejs',
      'karma-chai'
    ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    }

  });
};
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53

2 Answers2

0

you are missing chai lib path files array in which is dependency to mocha.include it.

files : [
        'node_modules/jquery/**/*.js',
          'lib/angular/angular.js',
          'lib/angular/angular-*.js',
          '../test/lib/angular-mocks.js',
          '../test/lib/sinon-1.15.0.js',
          '../test/chai/chai.js',
          'js/**/*.js',
          '../test/unit/**/*.js',
          '**/*.html'
        ],
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53
  • @ RIYAJ KHAN JI still i m getting same error..... Chrome 49.0.2623 (Windows 7 0.0.0) ERROR Uncaught Error: Module name "chai" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded at C:/6-angularjs-fundamentals-m6-testing-exercise-files/Finished/DemoApp/node _modules/requirejs/require.js:143 – Anurag Bajpai Mar 19 '16 at 19:12
  • Please share test script – RIYAJ KHAN Mar 19 '16 at 19:14
  • THIS IS ONE MODULE OF THAT SCRIPT; 'use strict'; var chai = require('chai'); expect = chai.expect; chai.should(); describe('calendarHelper', function() { beforeEach(module('eventsApp')); it('should return January when given a zero', inject(function(calendarHelper) { expect(calendarHelper.getMonthName(0)).toBe('January'); })) }); – Anurag Bajpai Mar 19 '16 at 19:19
-1

I came across a similar situation just with Jasmine. I'd like to introduce my solution.

Try it what is written in the error message. There is a link to a website: http://requirejs.org/docs/errors.html#notloaded

//If this code is not in a define call,
//DO NOT use require('foo'), but use the async
//callback version:
require(['foo'], function (foo) {
    //foo is now loaded.
});

My case written for Jasmine in Coffee script looks like this:

sinon = require(['sinon', 'jasmine-sinon']) (foo)->

Now I can use sinon as an object in my unit test and can also follow the documentation of sinon, as well as jasmin-sinon.

LSR
  • 97
  • 1
  • 11
  • The return value of a `require` call with an array of dependencies is **not** a module, so the line `sinon = require([...])` cannot be right. – Louis Jul 15 '16 at 14:50
  • And if you try is out without "sinon ="? What happens then? – LSR Jul 15 '16 at 15:04
  • You have to use the callback form you've shown in your first snippet. – Louis Jul 15 '16 at 15:07
  • Looking again at your first snippet, I'm not sure I was clear enough with my previous comment. Let me try again. When you call `require([....])` the *only* way to get the module values is through the callback. So `require(['foo'], function (foo) { foo.something();})` but `var foo = require(['foo'])` (makes no difference whether a callback is actually given) won't work because the return value of `require([...])` is not a module. What it returns is not defined in the AMD spec. – Louis Jul 15 '16 at 16:19