karma icon indicating copy to clipboard operation
karma copied to clipboard

Tests with Angular Taking Too Long

Open GonchuB opened this issue 13 years ago • 2 comments

My Angular tests with Karma are taking too long and I don't really see why. My test suite is really small and is taking around 2 minutes to complete it. Here is the output of one of the runs:

./test.sh 
...........................
Total 27 tests (Passed: 27; Fails: 0; Errors: 0) (129360.00 ms)
  Chrome 28.0.1500.71 Linux: Run 27 tests (Passed: 27; Fails: 0; Errors 0) (129360.00 ms)

I'm just testing some services that have dependencies with each other. My jasmine test spec is something like this:

/* Login Service Unit Testing */
describe('LoginService', function () {

    beforeEach(module('.LoginMockService'));
    beforeEach(module('LoginService'));

    /* Credential definition */
    var correctCredentials = {'id': 'admin', 'password': '1234'};
    var wrongCredentials = {'id': 'sysadmin', 'password': '4321'};

    /* Login Service injection. Inject Mock Service */
    var LoginService;
    beforeEach(function () {
        var $injector = angular.injector(['LoginService', 'LoginMockService']);
        LoginService = $injector.get('LoginService');
    });

    /* Testing getter methods */
    describe('getters', function () {
        it('should return empty user', function () {
            expect(LoginService.getID()).toEqual('');
        });
        it('should return empty password', function () {
            expect(LoginService.getPassword()).toEqual('');
        });
    });
});

And my service is quite simple (its not the complete service, but im posting a part of it so you can see how im using the service factory):

// Generated by CoffeeScript 1.6.3
var name;

name = 'LoginService';

angular.module(name, []).factory(name, [
  'LoginMockService', function(MockService) {
    var LoginService, user;
    LoginService = {};
    user = {
      id: '',
      password: ''
    };
    LoginService.getID = function() {
      return user.id;
    };
return LoginService;
  }
]);

GonchuB avatar Jul 16 '13 14:07 GonchuB

Weird, can you share your karma.conf.js too ?

Also, can you check out the web inspector (in the browser), timeline tab and see where the time is actually being spent ?

Also, try http://localhost:9876/debug.html is it that slow too ?

vojtajina avatar Jul 22 '13 00:07 vojtajina

I was using JSTestDriver instead of Karma. Switched to Karma and worked like a charm (Y)

GonchuB avatar Jul 22 '13 01:07 GonchuB