title: Unit test for angular $resource based REST is not able resolve a required dependency karma/jasmine
body: <p>I am new in jasmine/karma to write unit test cases for Angular. I have one service which uses $resource object to make server call. I tried to write test case however getting error related to not able resolve a required dependency. Following are required details.</p>
  
  <p><strong>Application Code:</strong>
  <strong>User.js (User resource)</strong></p>
  
  <pre><code>//create User factory
  app.factory('User', ['$resource', function($resource) {
          return $resource('/users/:id', {id: '@id'}, {update: {method: 'PUT', isArray: false}});
      }]);
  </code></pre>
  
  <p>UserImplementation.js (User Service)</p>
  
  <pre><code>app.factory('UserImplementation', ['User', function(User) {
  
          var UserImplementation =
                  {
                      //Get user details for given fileid
                      getUser: function(userId, getUserCallback)
                      {
                          //Create FileOperation object
                          var userObj = new User();
  
                          //make server call to lock the file
                          userObj.$get({id: userId}, function(response) {
                              //invoke callback
                              if (getUserCallback) {
                                  getUserCallback(response);
                              }
                          });
  
                      },
                      //Get all user details
                      getAllUsers: function(getUsersCallback)
                      {
                          //make server call 
                          User.query(function(response) {
                              //invoke callback
                              if (getUsersCallback) {
                                  getUsersCallback(response);
                              }
                          });
                      }
  
                  };
  
          return UserImplementation;
      }
  ]);
  </code></pre>
  
  <p><strong>Karma/Jasmine Test code:</strong>
  <strong>UserMock.js (ClientUnitTestData.js is having all the test data)</strong></p>
  
  <pre><code>var UserMock = {
      $get: function(userId) {
          return ClientUnitTestData.user;
      },
      query: function(userId) {
          return ClientUnitTestData.user;
      }
  };
  </code></pre>
  
  <p><strong>UserImplementation.test.js</strong></p>
  
  <pre><code>describe('UserImplementation tests', function() {
  
      // Load  module.
      beforeEach(module('ThemeLibrary'));
      // Setup the mock service in an ApplicationLoaderService module.
      beforeEach(module(function($provide) {
          $provide.value('User', UserMock);
      }));
  
      it('Check for all required functions',
              inject(function(UserImplementation) {
                  expect(angular.isFunction(UserImplementation.getUser)).toBe(true);
                  expect(angular.isFunction(UserImplementation.getAllUsers)).toBe(true);
              }));
  
  });
  </code></pre>
  
  <p><strong>Error:</strong>
  I am getting following error:
  Error: [$injector:unpr] <a href="http://errors.angularjs.org/1.3.0-beta.7/" rel="nofollow">http://errors.angularjs.org/1.3.0-beta.7/</a>$injector/unpr?p0=UserImplementationProvider%20%3C-%20UserImplementation</p>
  
  <p><strong>Edit: Updated karma config and used $httpBackend</strong>
  Following is updated UserImplementation.test.js</p>
  
  <pre><code>describe('UserImplementation tests', function() {
      var $httpBackend;
      // Load  module.
      beforeEach(module('ThemeLibrary'));
      // Setup the mock service in an UserImplementation module.
      beforeEach(inject(function(_$httpBackend_) {
          $httpBackend = _$httpBackend_;
          //Get user details
          $httpBackend.expectGET('/users/' + ClientUnitTestData.user._id).respond(ClientUnitTestData.user);
          //Get all users list
          var response = [];
          $httpBackend.expectGET('/users').respond(response.push(ClientUnitTestData.user));
      }));
  
      it('Check for all required functions',
              inject(function(UserImplementation) {
                  expect(angular.isFunction(UserImplementation.getUser)).toBe(true);
                  expect(angular.isFunction(UserImplementation.getAllUsers)).toBe(true);
              }));
  
      it('Test getUser() function',
              inject(function(UserImplementation) {
  
                  UserImplementation.getUser(ClientUnitTestData.user._id, function(response){
                      expect(response).toEqual(ClientUnitTestData.user);
                  });
  
  
  
              }));
  
  });
  </code></pre>
  
  <p>This is working fine. Is $httpBackend better approach compare to UserMock.js?</p>