Hi, something like this:
var response = {
> "message":"Success",
> "data":{
> "value": "bla"
> }
> };
> $httpBackend.whenPOST('/your/service/api').respond(200, response);
> $scope.yourEvent();
> $httpBackend.flush();
> });
You can see more information here:
https://docs.angularjs.org/api/ngMock/service/$httpBackend
Cheers,
Samuel Castro
On Thu, Apr 2, 2015 at 7:40 PM, Carol C <[email protected]> wrote:
> Hi, I am relatively new to Angular and unit testing. I have a working
> service that makes a HTTP get request and then does post processing through
> a series of functions. I'm not sure about how I would create a mock for a
> document object. Also I'm storing some of the interim data in a JS object
> where one of the values is a node list and am not sure how to make a mock
> for that. (I'm using Jasmine) Thank you.
>
> This is an excerpt from the service:
>
> return {
> getQuestionsArray: function() {
> $http.get(interviewUrl , {responseType: 'document'})
> .success(function(data, status, headers) {
> var categoriesAr = getCategories(data); //? how to mock data
> var questionsAr = getAllQuestions(data);
> var questionsObj = buildObj(categoriesAr, questionsAr);
> var fixedQuestionsObj = fixQuestionsObj(questionsObj);
> var questionsObj2 = getCodingQuestionsPt1(data, fixedQuestionsObj);
> var questionsObj3 = getCodingQuestionsPt2(data, questionsObj2);
> deferred.resolve(questionsObj3);
> })
> ...
>
> --
> 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.
>
--
Samuel Castro
Full Stack Developer
(37) 9110-8850
--
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.