AngularJS setup

Hi,
       Is there a simple set of instructions to test AngularJS using Jasmine ? We have a complicated requireJS setup for testing our entire applications. But I am trying to code a simple test. So the minimum AngularJS configuration is sufficient.

Update :

Do I have to install these ?

 
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',


I setup an AngularJS projects and Jasmine specs. execute. But this doesn't.

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

    beforeEach(function (){
        //load the module
        
module('test');

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

    it('Should set date', function() {

        scope.date = '10/01/2015';
    });
});

Thanks,
Mohan

3 comments
Comment actions Permalink

what do you mean saying that 'it doesn't'? What errors do you see (if any)? What does your karma configuration file look like?

I'm attaching a project that shows the minimal required configuration



Attachment(s):
angular_karma.zip
0
Comment actions Permalink

I created an AngularJS project in the IDE. Now I have a new folder 'lib' inside which I placed the angular files.

I see this.

ReferenceError: module is not defined
     at Object.<anonymous> (C:/Users/476458/WebstormProjects/AngularJS/test/basic/testSpec.js:12:9)

 
module.exports = function(config){
  config.set({

    basePath : './',

    files : [
      'app/lib/angular.js',
      'app/lib/angular-route.js',
      'app/lib/angular-mocks.js',
      'app/components/**/*.js',
      'app/view*/**/*.js',
        'app/**/*.js'
    
],

      // list of files / patterns to load in the browser
      files
: [
          'test/**/*Spec.js'
      
],
    autoWatch : true,

    frameworks: ['jasmine'],

    browsers : ['Chrome'],

    plugins : [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-jasmine',
            'karma-junit-reporter'
            
],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    
}

  });
};
0
Comment actions Permalink

Usually such error means that angular-mocks.js is missing/not included in karma.config/included in wrong order (as 'module' is defined in the
angular-mocks.js). Does the project I've provided work for you?

0

Please sign in to leave a comment.