mercredi 18 février 2015

Karma Browserify Dependency Injection not working

So i have recently added the Karma test runner to my commonJS project but when trying too access the app in my unit tests it claims.



[$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it.



this is my configuration: karma.conf.js



// Karma configuration
// Generated on Tue Feb 10 2015 10:08:30 GMT-0500 (EST)

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: http://ift.tt/1ft83uu
frameworks: ['browserify','mocha'],

// list of files / patterns to load in the browser
files: [
'public/bower_components/angular/angular.js',
'public/bower_components/angular-route/angular-route.js',
'public/bower_components/angular-mocks/angular-mocks.js',

'public/js/app.js', //(concatted file including all the scripts that make the app
'test/unit/client/*_tests.*',
'test/unit/client/test-main.js'
],

browserify: {
debug: true
},

// these plugins will be require() by Karma
plugins: [
'karma-browserify',
'karma-mocha',
'karma-chai',
'karma-firefox-launcher',
'karma-spec-reporter'
],

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

// preprocess matching files before serving them to the browser
// available preprocessors: http://ift.tt/1gyw6MG
preprocessors: {
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: http://ift.tt/1ft83KQ
reporters: ['spec'],

// web server port
port: 9876,

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

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

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

// start these browsers
// available browser launchers: http://ift.tt/1ft83KU
browsers: ['Firefox'],

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


test-main.js



var tests = [];

for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
// console.log(file);
if (/\_tests\.js$/.test(file)) {
tests.push(file);
}
}
}


unit_tests.js



describe("Remote Retro Module Unit Tests", function () {
//var module;
var ctrl, scope, $httpBackend, service;

// Load the module with Controller to be tested
beforeEach(module('app'));

beforeEach(inject(function ($controller, $rootScope, _service_, _$httpBackend_, _$http_) {

// Create a new scope that's a child of the $rootScope
scope = $rootScope.$new();
service = _service_;
$httpBackend = _$httpBackend_;
}));

Aucun commentaire:

Enregistrer un commentaire