Skip to content

Using Karma with RequireJS & Angular? #938

Closed
daviesgeek opened this Issue Mar 6, 2014 · 1 comment

3 participants

@daviesgeek

I'm new to Karma and RequireJS and I'm trying to set up unit testing with my project. The project is based on angular-brunch-seed, but we've added RequireJS to it.
I cannot figure out how to load the correct modules. I am sure I'm doing something wrong, but I can't figure out what the problem is. I've tried different ways of loading the app in my test:

define(function (require) {  
  return{
    app: require('/base/app/app.js'),
    routes: require('/base/app/routes/index.js'),
    routesAdmin: require('/ba,se/app/routes/admin/index.js'),
    adminInit: require('/base/app/routes/admin/controllers/admin-init.js')
  }
});
require(['app'], function(app){
  console.log('app is loaded?');
});

require(['/base/app/configuration/index.js'], function(app){
  var configuration = require('configuration');
});

Nothing works. I get the error:

Uncaught Error: Module name "configuration" has not been loaded yet for context: _. Use require([])

Does anyone have suggestions to loading RequireJS in a Karma unit test?

@aymericbeaumet
Karma member

Hi Matthew,

There is a nice guide here explaining how to make Require.js works along with Karma.

I also made a simple example so you cab quickly see how to do, find it here.

This example might also help you.

@vojtajina vojtajina added the support label Mar 10, 2014
@vojtajina vojtajina closed this Mar 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.