I am setting up tests that use Jasmine and Karma to test my JavaScript. Karma runs in Node.js and starts a Chrome browser.
I keep getting and error "Chrome 28.0 (Windows) ERROR Script error. at :0" Upon tracing through things I realized that some of the objects I create in my code make AJAX cross-domain AJAX calls and when they do that my Karma tests crash.
I do not need these AJAX calls to succeed for my tests to succeed, however I would like them to not crash my Karma tests.
I am open to solve this issue in a wide variety of ways. Can I change my Karma/Chrome settings so the AJAX will not fail catastrophically? Can I override XMLHttpRequest so either the offending requests aren't made or no requests are made?
Notes: The test does not fail in the debug window even though that it is also making cross domain AJAX requests.
I have am using a testing library that overrides jQuery's AJAX. However, I have another library that is still making AJAX requests.
I am setting up tests that use Jasmine and Karma to test my JavaScript. Karma runs in Node.js and starts a Chrome browser.
I keep getting and error "Chrome 28.0 (Windows) ERROR Script error. at :0" Upon tracing through things I realized that some of the objects I create in my code make AJAX cross-domain AJAX calls and when they do that my Karma tests crash.
I do not need these AJAX calls to succeed for my tests to succeed, however I would like them to not crash my Karma tests.
I am open to solve this issue in a wide variety of ways. Can I change my Karma/Chrome settings so the AJAX will not fail catastrophically? Can I override XMLHttpRequest so either the offending requests aren't made or no requests are made?
Notes: The test does not fail in the debug window even though that it is also making cross domain AJAX requests.
I have am using a testing library that overrides jQuery's AJAX. However, I have another library that is still making AJAX requests.
Share asked Aug 5, 2013 at 19:32 JoeJoe 8,04218 gold badges57 silver badges86 bronze badges 2- And can't you just override the ajax methods of the other library? – mael Commented Aug 5, 2013 at 19:34
- I am using AMD and it would be difficult to set up, as far as I know. – Joe Commented Aug 5, 2013 at 20:15
2 Answers
Reset to default 6I was having a similar issue with CORS and AJAX, then I followed jhamm suggestion. Then, I got "ERROR [launcher]: Cannot start chrome_without_security Can not find the binary chrome_without_security".
Since my issue was with CORS, I found out here that I should add the new browser type to the browsers list on karma.conf.js.
I added it like this:
browsers: ['Chrome_without_security'],
customLaunchers:{
Chrome_without_security:{
base: 'Chrome',
flags: ['--disable-web-security']
}
}
After that, and since I only have this one browser, I don't have to use
karma start --browsers Chrome_without_security
I can just type
karma start
And it will call for the HeadlessChrome without security, meaning it won't find any problems with CORS.
If it really is a CORS issue, you can disable the cross-domain by starting karma like this:
karma start --browsers chrome_without_security
Chrome has the ability to be started with the security disabled
open -a Google\ Chrome --args --disable-web-security
And the Karma team just takes advantage of it.