title: Angular app test with Karma
body: <p>I'm new to Jasmine tests with Karma. I'm getting following error while executing the tests.</p>
  
  <p><a href="https://i.stack.imgur.com/kU3Dp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kU3Dp.png" alt="enter image description here"></a></p>
  
  <p>Here are my files.</p>
  
  <p><strong>message.service.js</strong>  // Service file</p>
  
  <pre><code>(function() {
  
    'use strict';
  
      angular.module("app").factory('MessageService', [MessageService]);
  
      function MessageService() {
          var service = {};
          //var gui = require('nw.gui');
  
        service.alert = function() {
          //gui.Window.open('/');
              //$window.open('/message');
              return 'hello';
        };
  
        return service;
      };
  
  })(); // IIFE
  </code></pre>
  
  <p><strong>message.service.spec.js</strong> // Service test file</p>
  
  <pre><code>describe('Message Service', function() {
  
    var messageService;
    beforeEach(angular.mock.module('app'));
  
    beforeEach(inject(function(_MessageService_) {
      messageService = _MessageService_;
    }));
  
    it('should exist', function() {
      expect(messageService).toBeDefined();
    });
  
    it('should return hello', function() {
      expect(messageService.alert()).toEqual('hello');
    });
  
  });
  </code></pre>
  
  <p><strong>app.module.js</strong> // Main app file</p>
  
  <pre><code>(function() {
  
    'use strict';
  
    angular.module("app", ['ngRoute', 'ui.bootstrap', 'ui.router']);
  
      /*angular.module("app").run(['$rootScope', 'StartupService', function($rootScope, startupService){
          startupService.init($rootScope);
      }]);*/
  
  })(); // IIFE
  </code></pre>
  
  <p>If I change following line in message.service.js</p>
  
  <pre><code>angular.module("app").factory('MessageService', [MessageService]);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>angular.module("app",[]).factory('MessageService', [MessageService]);
  </code></pre>
  
  <p>Then tests work fine but application will not work(due to re initiation of module I guess). How can I make my app to work for both tests and normal app execution? Appreciate your help</p>