Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:30:20+00:00 2026-06-17T08:30:20+00:00

Pretty new to AngularJS and got a mock $httpBackend working as described in the

  • 0

Pretty new to AngularJS and got a mock $httpBackend working as described in the docs (see here:http://docs.angularjs.org/api/ngMockE2E.$httpBackend). I can reproduce the GET code e.g.:

$httpBackend.whenGET('/phones').respond(phones);

The POST, method, however, fails with an angular-mocks.js error. This is what I specify to happen on POST:

      $httpBackend.whenPOST('/phones').respond(function(method,url,data){
        console.log(data);
        phones.push(angular.fromJson(data));
  });

This is how I call the POST from the controller:

  var newPhone = {name:'New Phone'};
  $http.post('/forecasts/types.json', newPhone);

And this is what I see in the console in response:

{"name":"New Phone"}  app.js:167

Uncaught TypeError: Cannot read property '2' of undefined angular-mocks.js:876
(anonymous function) angular-mocks.js:876
completeOutstandingRequest angular.js:2930
(anonymous function) angular.js:3209

My code looks pretty much the same as the docs. The function is called when POSTed to but I can’t figure out why it won’t run.

Edit (thanks to Josh David Miller for his comment re a fiddle) Here is a fiddle that reproduces the error: http://jsfiddle.net/elcabo/btbds/3/
The fiddle is based on the example in the Angular docs (http://docs.angularjs.org/api/ngMockE2E.$httpBackend) and the angular fiddle for mockE2E $httpBackend (http://jsfiddle.net/vojtajina/DQHdk/)

Has anyone encountered this before or have any ideas on how to attack this?

I’ve searched pretty wide for a solution/relevant posts but can’t find any, so any pointers would be greatly appreciated.

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:30:21+00:00Added an answer on June 17, 2026 at 8:30 am

    I updated your jsFiddle, which now works: http://jsfiddle.net/joshdmiller/EgMpe/.

    First, the version of AngularJS was extraordinarily old. I updated it from 0.10.6 to 1.0.3. With that change came many syntactic changes, which you can find in the fiddle.

    But the issue you were having was from not returning a value in your $httpBackend.whenPOST method. The respond method is expected to return a value indicating the status, response body, and headers. The verbose example I included in the working fiddle is:

    $httpBackend.whenPOST('/phones').respond(function(method, url, data, headers){
      console.log('Received these data:', method, url, data, headers);
      phones.push(angular.fromJson(data));
      return [200, {}, {}];
    });
    

    The array returned is a response status of 200, an empty response body, and an empty set of headers (i.e. use the defaults).

    I also added a whenGET so you can see them working together:

    $httpBackend.whenGET('/phones').respond(function(method,url,data) {
      console.log("Getting phones");
      return [200, phones, {}];
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty new to Perl so there may be a very obvious solution here. I'm
I am pretty new to python and pyramid. I am working on pyramid application
Im pretty new to CI so bear with me here. I have just setup
Pretty new to all this REST stuff. I'm designing my API, and am not
Am pretty new to SharePoint, am working on creating a custom permission that I
Im pretty new to Linux in general. Ive just been following this tutorial(http://net.tutsplus.com/tutorials/php/how-to-setup-a-dedicated-web-server-for-free/) to
Pretty new flixel/AS3 user here, though not entirely new to coding. Anyways, the error
pretty new to vb and I want to get a tab control working. so
I'm pretty new to Spring, so apologies if I don't see the obvious answer
Pretty new here. But before I ask my question, I'm not looking for teh

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.