Pretty new to AngularJS and got a $ httpBackend layout that works as described in the docs (see here: http://docs.angularjs.org/api/ngMockE2E.$httpBackend). I can reproduce the GET code, for example:
$httpBackend.whenGET('/phones').respond(phones);
The POST method, however, fails with the angular -mocks.js error. This is what I point to in POST:
$httpBackend.whenPOST('/phones').respond(function(method,url,data){ console.log(data); phones.push(angular.fromJson(data)); });
This is how I call POST from the controller:
var newPhone = {name:'New Phone'}; $http.post('/forecasts/types.json', newPhone);
And here 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 about the same as documents. The function is called when POSTed is sent, but I cannot understand why it will not work.
Edit (thanks to Josh David Miller for his comment again for the fiddle) Here is a fiddle that reproduces the error: http://jsfiddle.net/elcabo/btbds/3/ The fiddle is based on an example in Angular docs (http: //docs.angularjs. org / api / ngMockE2E. $ httpBackend) and Angular script for mockE2E $ httpBackend (http://jsfiddle.net/vojtajina/DQHdk/)
Has anyone come across this before or had any ideas on how to attack this?
I searched fairly broadly for solution / relevant posts, but can't find, so any pointers would be very appreciated.
Many thanks.
angularjs
coderigo
source share