Did you ever figure out what was wrong? I'm using the angular translate
module to pull static resource, but this means I need to configure the
$httpBackend before .config is executed. Any idea how to do this?
On Tuesday, April 23, 2013 at 2:22:15 AM UTC-5, Pascal Precht wrote:
>
> Okay, turned out something else is wrong. Will update this post when I
> know more.
>
> On Monday, April 22, 2013 9:11:50 PM UTC+2, lorenzofox3 wrote:
>>
>> you mean the plunker ? I don't see any link sorry
>>
>> But maybe what you want to achieve would be something like that ? :
>>
>> angular.module('myModule',[]).service('myService',['$http', function
>> (http) {
>> var dataFromServer;
>>
>> http.get('/someUrl').success(function (data) {
>> dataFromServer=data;
>> });
>>
>> this.getData= function () {
>> return dataFromServer;
>> }
>>
>> }]);
>>
>> And you can test it like this :
>>
>> describe('my module', function () {
>>
>> beforeEach(module('myModule'));
>>
>> describe('my service ', function () {
>>
>> var http;
>>
>> //configure http before the service is called by injector (see
>> inject(function(){...})
>> beforeEach(inject(function ($httpBackend) {
>> http=$httpBackend;
>> http.when('GET','/someUrl').respond({someProp:'someValue'});
>> }));
>>
>> afterEach(function () {
>> http.verifyNoOutstandingExpectation();
>> http.verifyNoOutstandingRequest();
>> });
>>
>> iit('shoul have set my value',inject(function (myService) {
>> http.flush();
>> expect(myService.getData()).toEqual({someProp:'someValue'});
>> }));
>>
>> });
>>
>> });
>>
>>
>> cheers
>>
>> Laurent
>>
>> Le lundi 22 avril 2013 20:21:23 UTC+2, Pascal Precht a écrit :
>>>
>>> You already got it :)
>>>
>>> On Monday, April 22, 2013 6:36:40 PM UTC+2, lorenzofox3 wrote:
>>>>
>>>> However if you provide a plunker of what you want to achieve we may be
>>>> able to understand and help you
>>>>
>>>> On Monday, April 22, 2013 6:31:25 PM UTC+2, lorenzofox3 wrote:
>>>>>
>>>>> Sorry,
>>>>>
>>>>> At config time, the injector can only access the providers, however I
>>>>> am not sure there is much you can do with httpBackendProvider.
>>>>> You should check the source code of ngMock module.
>>>>>
>>>>> Sorry again.
>>>>>
>>>>> Laurent
>>>>>
>>>>> On Monday, April 22, 2013 11:45:04 AM UTC+2, Pascal Precht wrote:
>>>>>>
>>>>>> Hey,
>>>>>>
>>>>>> I wonder if there's a way to get an instance of $httpBackend in
>>>>>> module().config(); . The reason for that is, that I have a service,
>>>>>> which
>>>>>> fires a XHR with $http service, when it gets invoked by $injector.
>>>>>> To setup proper tests, $httpBackend mock needs to be configured,
>>>>>> before my service gets injected.
>>>>>>
>>>>>> So is there any way to get $httpBackend in config(); ? If not, what
>>>>>> would be the way to test if my services fires a proper request during
>>>>>> instantiation? Or is it a design fail?
>>>>>>
>>>>>
--
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.