简体   繁体   中英

testing module controllers, factories, services, etc in Angular.js

I can't get my unit tests to work in Angular.js when I've defined my components in a module. Here is my unit test using Karma test runner with Jasmine. I've looked at several posts and it looks like this is the way to test module controllers. However, my test runner output says that 'module is not defined'. I'm not sure what I am missing. Do I need to configure something in karam.conf.js?

describe('bulkEditor factories', function() {
    beforeEach(module('BulkEditor'));

    it('should see the controller', inject(function($controller) {
        expect($controller('GroupController'.toBeTruthy()));
    }));

});

Here is a section from my karma.conf.js file that shows the list of files that get included:

files = [
  JASMINE,
  JASMINE_ADAPTER,
  'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js',
  'app/js/app/**/*.js',
  'test/*.spec.js'
];

The module and inject functions are defined in the angular-mocks.js file. You can grab it from http://code.angularjs.org/ (ex.: http://code.angularjs.org/1.0.6/angular-mocks.js ).

I must say that I've necer used Karma with files referenced via CDN but in any case angular-mocks.js is not deployed on CDN so you will have to get it from http://code.angularjs.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM