You can replace service b with a spy or mock object using the $provide
service. Check out this blog under providing custom
mocks: http://www.benlesh.com/2013/06/angular-js-unit-testing-services.html
Gordon
On Thursday, April 3, 2014 9:47:15 AM UTC-5, Pudas Jriest wrote:
>
> One idea I had was to change the karma config (im my case) so that the
> actual serviceB js file isn't included, and instead the mock version (which
> the same module / service name). I'd rather not have to do that though,
> seems like there should be a better was that does not need me to exclude
> certain files and include others; i.e to control programmatically.
>
> On Thursday, April 3, 2014 3:13:16 PM UTC+1, Pudas Jriest wrote:
>>
>> Hi all,
>>
>> I have a Controller, depending upon a service (service a), which in turn
>> depends upon another service (service b).
>>
>> >>Controller
>> >>>>ServiceA
>> >>>>>>ServiceB
>>
>> I am writing a test (at least conceptually) at the Controller level.
>>
>> I am able to introduce a mock version of Service A, something like this
>> (please comment if this is bad, first of all):
>>
>> var mockServiceA = ....;
>>
>> beforeEach(inject(function($rootScope, $controller) {
>> scope = $rootScope.$new();
>> $controller("Controller", {
>> $scope: scope,
>> serviceA: mockServiceA
>> });
>> }));
>>
>> Anyway, the above is not what I want to do. What I really want to mock
>> is ServiceB. I just want to somehow say, "in the life of this runtime,
>> always use an alternative version of ServiceB"?
>>
>> What is the best way to do this?
>>
>> Thank you,
>>
>> PJ.
>>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.