AsmaG AsmaG - 1 year ago 253
CoffeeScript Question

CoffeeScript Code UnitTest AngularJS - Jasmine - Karma

I am trying to write unit test to my Controllers and services of my Ionic project written with CoffeeScript. I chose to use Karma and Jasmine. The problem is it doesn't interpreter coffeeScript. That's why I used this plugin karma-coffee-preprocessor so that it will be possible. I don't know if I am doing it right.

I installed the plugin with the command ;

npm install --save-dev karma-coffee-preprocessor

I then configured my test config file as follows:

module.exports = function(config) {

basePath: '',
frameworks: ['jasmine'],
files: [

exclude: [

preprocessors: {
'../src/scripts/**/*.coffee': ['coffee']

coffeePreprocessor: {
options: {
bare: true,
sourceMap: false
transformPath: function(path) {
return path.replace(/\.coffee$/, '.js')

reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity

But when I try to start my test I have this error :

Can not load "coffee", it is not registered!
Perhaps you are missing some plugin?
throw error('No provider for "' + name + '"!');

Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)
at error (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:22:12)
at Object.parent.get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /opt/node/lib/node_modules/karma/lib/server.js:138:20
at Array.forEach (native)
at Server._start (/opt/node/lib/node_modules/karma/lib/server.js:137:21)
at invoke (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/opt/node/lib/node_modules/karma/lib/server.js:102:18)
at (/opt/node/lib/node_modules/karma/lib/cli.js:243:26)
at Object.<anonymous> (/opt/node/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)

Can anyone help me ?
I having trouble making these unit tests, and I don't know if I am doing things the right way.

Answer Source

First of all you need to install jasmine framework via npm and add it to the frameworks collection in karma config file:

$ npm install karma-jasmine --save-dev

then add:

frameworks: ['jasmine']

to karma config file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download