I am running specs
and notice the following error in the browser window
zone.js:2990 Access to XMLHttpRequest at 'ng:///DynamicTestModule/NewPracticeQuestionComponent_Host.ngfactory.js' from origin 'http://localhost:9876' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
I suppose somewhere in my application, some message has been sent out which is causing CORS
issue. I assume its the web server used by Karma
which is blocking the request.
Could I configure Karma
to disable CORS
policy?
We call this the CORS error. CORS error due to browser's same origin policy. To get around this, you need to tell your browser to enable your client and your server to share resources while being of different origins. In other words, you need to enable cross-origin resource sharing or CORS in your application.
To get rid of a CORS error, you can download a browser extension like CORS Unblock. The extension appends Access-Control-Allow-Origin: * to every HTTP response when it is enabled. It can also add custom Access-Control-Allow-Origin and Access-Control-Allow-Methods headers to the responses.
Karma handles the process of creating HTML files, opening browsers and running tests and returning the results of those tests to the command line. If you use the Angular CLI to manage projects it automatically creates stub Jasmine spec files for you when generating code.
Run your test with --sourcemaps=false
and you will get the right error messages.
This is an issue here : https://github.com/angular/angular-cli/issues/7296
Also, Shorthand :
ng test -sm=false
As of angular 6 the command is:
ng test --source-map=false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With