0

it is working well with karma-jasmine.....but not working with karma-mocha...y??

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/lib/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'
   }

 });

};

MY SAMPLE CODE:::

'use strict';

describe('calendarHelper', function() {
   beforeEach(module('eventsApp'));

   it('should return January when given a zero',       inject(function(calendarHelper) {
      expect(calendarHelper.getMonthName(0)).toBe('January');
   }))
});
David Losert
  • 4,652
  • 1
  • 25
  • 31
  • 3
    Possible duplicate of [Uncaught Error: Module name "lib/chai" has not been loaded yet for context: use require(\[\])](http://stackoverflow.com/questions/36104971/uncaught-error-module-name-lib-chai-has-not-been-loaded-yet-for-context-use) – Louis Jul 15 '16 at 16:12

1 Answers1

0

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

Use this in your spec file:

//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 and Sinon in Coffeescript 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
  • Please don't post identical answers to multiple questions. Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, *tailor your answers to the question.* – Paul Roub Jul 15 '16 at 16:35
  • Why aren't the questions flagged before? – LSR Jul 15 '16 at 17:13