Jasmine mock error

117 views
Skip to first unread message

Mohan Radhakrishnan

unread,
Jan 29, 2015, 3:57:24 AM1/29/15
to jasmi...@googlegroups.com
Hi,
          I have this mock test and my module 'Test' is simple. But when I uncomment the section at the end I get an error. The error message is at the end of the mail.
 
The uncommented section in the code works fine. What could be the problem ?
 
----------------------------------------
'use-strict';
angular.module('Test', []);
 
----------------------------------------
describe('Test Controller', function() {
    var $scope, $rootScope, $q, controller, mockedApiService, queryDeferred;
    //What is the expected response ?
    var expectedResponse = [{ suffix: 'Mr.'}, { prefix: 'Miss'}];
    beforeEach(module('Test'));
    beforeEach(inject(function(_$rootScope_, _$q_, $controller) {
          $q = _$q_;
          $rootScope = _$rootScope_;
          $scope = $rootScope.$new();
          mockedApiService = {
            query: function() {
              queryDeferred = $q.defer();
              return queryDeferred.promise;
            }
          }

         spyOn(mockedApiService, 'query').andCallThrough();
          // inject the mocked Service into the controller.
          controller = $controller('TestController', {
            '$scope': $scope,
            'ServiceApi': mockedApiService
          });
    }));

// describe('When a asynchronous mock call is setup', function() {
//     beforeEach(module('Test'));
//     beforeEach(function() {
//       queryDeferred.resolve(expectedResponse);

//       $rootScope.$apply();
//     });
//     it('and the call to the service is issued ', function() {
//       expect(mockedApiService.query).toHaveBeenCalled();
//     });
//   });
});
 
 
 
Chrome 40.0.2214 (Windows 7) Test Controller When a asynchronous mock call is se
tup and the call to the service is issued  FAILED
        Error: [$injector:modulerr] Failed to instantiate module Test due to:
        Error: [$injector:nomod] Module 'Test' is not available! You either miss
pelled the module name or forgot to load it. If registering a module ensure that
 you specify the dependencies as the second argument.
        http://errors.angularjs.org/1.3.0/$injector/nomod?p0=Test
            at d:/karma-requirejs-Angular/lib/angular/angular.js:80:12
            at d:/karma-requirejs-Angular/lib/angular/angular.js:1797:17
            at ensure (d:/karma-requirejs-Angular/lib/angular/angular.js:1721:38
)
            at module (d:/karma-requirejs-Angular/lib/angular/angular.js:1795:14
)
            at d:/karma-requirejs-Angular/lib/angular/angular.js:4064:22
            at forEach (d:/karma-requirejs-Angular/lib/angular/angular.js:335:20
)
            at loadModules (d:/karma-requirejs-Angular/lib/angular/angular.js:40
 
Thanks,
Mohan

Mohan Radhakrishnan

unread,
Feb 16, 2015, 12:34:01 AM2/16/15
to jasmi...@googlegroups.com
Any suggestions Please ?

Thanks,
Mohan
Reply all
Reply to author
Forward
0 new messages