Thank you André
Farzat<https://plus.google.com/u/1/104871698073217223357?prsrc=4> now
i am able test with config values.


On Tue, May 27, 2014 at 11:07 PM, André Farzat <[email protected]>wrote:

> I believe that the right way to add a constant ( or a configuration
> variable ) is to use `.value` instead of `.config`
>
> Have a look in Configuration 
> Blocks<https://docs.angularjs.org/guide/module#configuration-blocks>in the 
> doc.
>
> If you do `angular.module('Signup', []).value('ajaxURL', { ... });` you
> can inject it later as `function( ajaxURL ){ ... }`.
> So, in your tests, you can mock the 
> value<http://stackoverflow.com/a/15913333/1327401>and inject in the 
> controller.
>
> On Tuesday, May 27, 2014 10:24:08 AM UTC-3, Ramesh Paul wrote:
>>
>> I am developing angularjs app and i have defined app configuration data.
>> When i unit test my controller i am getting error if i remove app
>> configuration unit tests are running with out errors.
>>
>> My code is here app.js
>>
>> var signup = angular.module('Signup', []);
>>     signup.config("ajaxURL",{"signupSubmit": 
>> "/signup/submit","signupCheckEmailAvailability": "/signup/checkemail"});
>>
>>     signup.factory('SignupService',['$http','ajaxURL',function($http,URL){
>>         return {
>>           submit: function(signupData){
>>                 console.log("in submit service--");
>>                 console.log(signupData);
>>                 var promise = $http.post((URL.signupSubmit).toString(), 
>> signupData).then(function(response){
>>                     return response;
>>                 });
>>                 return promise;
>>           },
>>           checkEmailAvailability: function(emailData){
>>               var promise = 
>> $http.post((URL.signupCheckEmailAvailability).toString(),emailData).then(function(response){
>>                   return response;
>>               });
>>               return promise;
>>           }
>>         };
>>     }]);
>>
>>     signup.controller('SignupCtrl',['SignupService', 
>> '$scope',function(Signup, $scope){
>>
>>         $scope.signupPromise;
>>         $scope.submitSignupForm = function(signupData){
>>             $scope.signupPromise = Signup.submit(signupData);
>>             signupSubmitEvent();
>>         }
>>
>>         function signupSubmitEvent(){
>>             $scope.signupPromise.then(function(response){
>>                 console.log("http response");
>>             });
>>         }
>>
>>     }]);
>>
>> appSpec.js
>>
>> 'use strict';
>> describe('signup unit tests', function() {
>> var signup, scope, $httpBackend, ctrl;var userData = 
>> {"userid":"2","email":"[email protected]","clientId":"123456789","clientSecret":"a1b2c3d4e5f6","accessToken":"AP16MD3217"};
>>
>> beforeEach(module('Signup'));
>>
>> beforeEach(inject(function($injector, _$rootScope_, $controller, 
>> _SignupService_){
>>
>>     $httpBackend = $injector.get('$httpBackend');
>>
>>     scope = _$rootScope_.$new();
>>     var Signup = _SignupService_;
>>
>>     ctrl = $controller('SignupCtrl', {Signup: Signup, $scope: scope});}));
>>
>> it("simple testing", function(){
>>     console.log("in simple test");
>>     $httpBackend.expectPOST("/signup/submit/", userData).respond([{name: 
>> 'Nexus S'}, {name: 'Motorola DROID'}]);
>>     $httpBackend.flush();
>>     scope.submitSignupForm(userData);});
>>
>> });
>>
>> Can any on help me how to add configuration data to the unit test?
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/onpsdhq3Jm8/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>



-- 
Regards
Ramesh Babu Ch

-- 
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.

Reply via email to