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