Jsdom: Disabling same origin policy check

Created on 15 Aug 2017  ·  4Comments  ·  Source: jsdom/jsdom

I am trying to unit test some ajax calls (written in Scala.js) with jsdom and I would like to disable same origin policy checks.

How can I do that ? I was searching this on the net but found nothing.

Most helpful comment

+1 to @arendjr's suggestion. JSDOM's utility is not only as a browser emulator but also as a testing platform and pretty much anything which makes testing harder has the unfortunate affect of reducing testing. It takes a lot of nock ceremony to work around JSDOM's cross-origin checks which leaves test writers working on code incidental to their intended tests.

All 4 comments

You cannot. jsdom acts like a browser, including same-origin checks.

Make sure you are setting the URL correctly though.

Many thanks for the info.

At least Chrome has a command-line argument to disable CORS checks. Why can't JSDOM provide a developer-friendly way to disable it?

+1 to @arendjr's suggestion. JSDOM's utility is not only as a browser emulator but also as a testing platform and pretty much anything which makes testing harder has the unfortunate affect of reducing testing. It takes a lot of nock ceremony to work around JSDOM's cross-origin checks which leaves test writers working on code incidental to their intended tests.

Was this page helpful?
0 / 5 - 0 ratings