Skip to content

Instantly share code, notes, and snippets.

@stevenh77
Created October 24, 2014 15:45
Show Gist options
  • Save stevenh77/d95e66c689462e61f801 to your computer and use it in GitHub Desktop.
Save stevenh77/d95e66c689462e61f801 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/questions/14773269/injecting-a-mock-into-an-angularjs-service
angular.module('myModule')
.factory('myService', function (myDependency) {
return {
useDependency: function () {
return myDependency.getSomething();
}
};
});
describe('Service: myService', function () {
var myService,
mockDependency;
beforeEach(module('myModule'));
beforeEach(function () {
mockDependency = {
getSomething: function () {
return 'mockReturnValue';
}
};
module(function ($provide) {
$provide.value('myDependency', mockDependency);
});
});
it('should return value from mock dependency', inject(function (myService) {
expect(myService.useDependency()).toBe('mockReturnValue');
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment