1
votes

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?Vadim
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'Tetiana Chupryna

2 Answers

1
votes

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.

0
votes

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.