1

I try to test my AngularJS controller with Jasmine in RubyMine.

Here is my test

'use strict';

describe('MainCtrl', function(){ var scope;

beforeEach(module('myModule'));

beforeEach(inject(function($rootScope) { scope = $rootScope.$new(); }));

it('should define more than 5 awesome things', inject(function($controller) { expect(scope.awesomeThings).toBeUndefined();

$controller('MainCtrl', {
  $scope: scope
});

expect(angular.isArray(scope.awesomeThings)).toBeTruthy();
expect(scope.awesomeThings.length > 5).toBeTruthy();   })); });

I use Karma for run this test. For configure RubyMine to run tests I made all as it was written in those tutorials https://www.jetbrains.com/ruby/webhelp/preparing-to-use-karma-test-runner.html https://www.jetbrains.com/ruby/webhelp/running-unit-tests-on-karma.html

Here is my Karma config file

'use strict';

module.exports = function(config) {

config.set({ autoWatch : false,

frameworks: ['jasmine'],

browsers : ['PhantomJS'],

plugins : [
    'karma-phantomjs-launcher',
    'karma-jasmine'
]   }); };

But I got this error when I tried to run my test

src/app/main/main.controller.spec.js:3 describe('MainCtrl', function(){ ^ ReferenceError: describe is not defined

at Object.<anonymous> (src/app/main/main.controller.spec.js:3:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3

How can I fix this? I'd be glad for any help.

2
  • Are you running your test using the Karma runner or the node runner? Commented Jan 4, 2015 at 22:08
  • I thought that I used Karma runner but in fact it was node runner. Silly me! But I have a problem now as Karma runner doesn't find my test and I get 'Empty test suite' Commented Jan 5, 2015 at 14:36

2 Answers 2

1

In addition to using the karma runner. You need to add something like the following to your config:

files: [
  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'js/**/*.js',
  '../../specs/*.js'
],

with appropriate list of files. You need to include all specs as well as any files you need loaded for your app, such as angular and other libraries.

Sign up to request clarification or add additional context in comments.

Comments

0

Add this to your plugins 'karma-spec-reporter' and then you should be able to run it - I believe it is failing because it is looking for the spec reporter.

1 Comment

I've added 'reporter' to my plugins, but unfortunately this trick doesn't work for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.