Pregunta

I can't seem to get started with karma. While it's trying to load the service it fails. Here's the spec file:

describe('Service: angelloModel', function () {

    beforeEach(module('Angello'));

    var modelService;

    beforeEach(inject(function (angelloModel) {
        modelService = angelloModel;
    }));

    describe('#getStatuses', function () {
       it('should return seven different statuses', function () {
          expect(modelService.getStatuses().length).toBe(7);
        });
     })
});

The karam config section for files to use:

    files: [
                'bower_components/angular/angular.js',
                 app.js',
                 'tests/*.spec.js'
            ],

and finally the error:

INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Mac OS X 10.9.2)]: Connected on socket edWal-wdFxcFp1KPQndO with id 43277901
 Chrome 34.0.1847 (Mac OS X 10.9.2) Service: angelloModel encountered a declaration exception FAILED
    ReferenceError: module is not defined
        at null.<anonymous> (/Users/e002678/dev/Dropbox/angular/ng-inaction/tests/angelloModel.spec.js:3:16)
        at /Users/e002678/dev/Dropbox/angular/ng-inaction/tests/angelloModel.spec.js:1:1
Chrome 34.0.1847 (Mac OS X 10.9.2): Executed 1 of 1 (1 FAILED) ERROR (0.015 secs / 0.013 secs)

here's the service definition:

myModule.factory('angelloModel', function () {
var getStatuses = function () {
    ...
};

var getTypes = function () {
  ...
};

var getStories = function () {
  ...
};

return {
  getStatuses: getStatuses,
  getTypes: getTypes,
  getStories: getStories
};

});

Thank you!

¿Fue útil?

Solución

You need to include angular-mocks.js in your files array, after angular and before your test files.

Here's an example config from a template project of mine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top