$httpBackend not working fine with ngMocksE2E module - javascript

I am making a simple application frontend with Angular JS (v1.2.16). I will be using REST API but that API is not build yet and its specs are complete. So based on the Link : $httpBackend
- service in module ngMockE2E, I can mock API request along with my development Process.
I have tried to do the same and come up with a demo but its giving me an error where I feel that its failing for passThrough function.
demo is available on this Link http://ngdemo.ws01.tranceserve.com/#/projects.
Now it gives me an error stating :
Error: Unexpected request: GET /views/projects.html
No more request expected
Please Help.

$httpBackend isn't prepared to handle the request for the views. Add a passthrough for your views:
$httpBackend.whenGET(/^\/views\//).passThrough();

Related

Mirage `passthrough` is not working

I'm trying to use passthrough for a POST request in this Ember project
this.passthrough('/thirdeye/entity?entityType=ANOMALY_FUNCTION');
This is what the call looks like in app/mirage/config.js.
I got the following error:
Mirage: Your Ember app tried to POST '/thirdeye/entity?entityType=ANOMALY_FUNCTION',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?
Clearly, I've added that call to the config file, but it's not being picked up. I read that passthrough only works for >= jquery 2.x, which my project is.
Does anyone know what else could cause this?
I found out the problem was I had to do this.passthrough('/thirdeye/***'); since the call has query params. It works now.

Laravel: RuntimeException in compiled.php line 7772: when making angular http requests

Hi i get this error sometimes when i use angular $http methods on a Laravel api. please help me to understand what this error is and anything i can do to get it solved. I have put the error log in a codepen for better viewing.
here is the link to the code pen: http://codepen.io/anon/pen/GjzJOX
http://codepen.io/anon/pen/GjzJOX
Run the following under project root:
php artisan key:generate

Get $httpProvider from jquery so I can intercept messages

I have an angular app with javascript code I can't touch (3rd party code).
I'd like to intercept the http messages from outside of angular. I have figured out how to get the controller and injector and can get the $http service, but I can't seem to get the $httpProvider so I can add an intercept something like here
Code I've got so far is (it's actually in a timeout but I left that out for brevity),
$(window).load(
...
var injector = angular.element('#myBody').injector();
var httpProvider = injector.get('$httpProvider ');
httpProvider.interceptors.push(function ($q) {
...
but httpProvider isn't defined, $http is defined but it's not the same as the provider - I'm fairly new to angular, so is there any way to get the provider? Version is 1.1.5
Just to close the question - as calebboyd said:
Perhaps you can extend the app.
angular.module("3rdPartyApp").config(function($httpProvider){...});
This works.

Can't get Angular $resource to send proper Headers

I'm building a prototype Angular app, using Parse as a temporary RESTful back end (Until the real restful backend is completed)
I've setup a Factory with $resource() but I'm constantly getting a 401 unauthorized.
Right now my factory looks like this (APPIDKEY AND APIKEY are redacted of course)
app.factory('eventFactory', ['$resource', function($resource){
return $resource('https://api.parse.com/1/classes/Events',{},
{headers:{"X-Parse-Application-Id": "APPIDKEY",
"X-Parse-REST-API-Key": "APIKEY"}});
}
]);
I've also tried writing the $resrouce like this.
$resource('https://myAppID:javascript-key=myJavaScriptKey#api.parse.com/1/classes/Events');
But that also returns a 401. however if I copy and paste that URL into my browser the screen prints out all the objects in the request.
I've done extensive googling and read the $resource docs many times but I still can't quite figure this out. I'm thinking it has to do with Cross-Origin policy but the parse documentation says
'For Javascript usage, the Parse Cloud supports cross-origin resource sharing, so that you can use these headers in conjunction with XMLHttpRequest.' So I'm kinda stumped.
Any help is much appreciated. Thanks!
Adding these two lines inside my module.config function fixed it.
$httpProvider.defaults.headers.common['X-Parse-Application-Id']="APPIDKEY"
$httpProvider.defaults.headers.common['X-Parse-REST-API-Key']="RESTAPIKEY"
where APPIDKEY and RESTAPIKEY equal the keys provided from Parse.com

How do I write my protractor scenarios to assert on http response errors?

I'm using protractor to test my angular client (server is built using Python Google App Engine).
I would like my protractor test to have an assertion on the http response from a POST that is triggered by clicking on a form button... like so:
describe('Pointless Form Post Test', function() {
beforeEach(function() {
browser.get('/myform');
});
it('should successfully populate a form, post it, and not return error', function() {
element(by.model('form_summary')).sendKeys('Some input text');
element(by.model('form_details')).sendKeys('Lots of detailed text');
element(by.id('formBtn')).click();
--> SOME FORM OF ASSERTION FOR HTTP 500 ERROR RESPONSE <
})
});
How do I assert on the response from the server that is received after clicking the button?
NOTE: I have this sneaking suspicion I don't have the right understanding of the scope of E2E testing that protractor is meant to address... but this feels like something I would need for my E2E testing. I was writing a test against my POST handler and noticed the server was sending back 500 errors (a bug in the server). Was hoping protractor could be used to catch these issues.
Protractor allows you to access the output of the browser console; you can parse its output and check for errors, like the one a 500 would throw.
Here's an example (not by me) of a similar case:
https://github.com/juliemr/protractor-demo/blob/master/howtos/browserlog/spec.js
If this is faithful to the intended use of Protractor is arguable; like another poster has commented above, you should really display the error in your interface and use Protractor to test such display, not the error itself.

Categories