Created
October 24, 2014 15:45
-
-
Save stevenh77/d95e66c689462e61f801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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