'disable CORS checking in jsdom on nodejs

Is it possible to disable the CORS checking functionality in the jsdom node module?

The CORS errors are particularly difficult to debug in my use case (clientside testing) and do not occur in the actual environment I am running the program.

Perhaps some environmental variable we can set when initializing the object? e.g.,

window = new jsdom.JSDOM(``,{
    cors : false,
}).window;


Solution 1:[1]

As stated in this issue on JSDOM Github repository, JSDOM acts like a browser and the same-origin policy applies.

It cannot be disabled from there.

The solution would be to add headers to the resource server allowing the origin of the client which makes the request.

Solution 2:[2]

Just set testURL in your jest.config.js to your API address.

Solution 3:[3]

Set window._origin to the requested origin such as http://www.example.com. Works for Jest 27.5.1.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pierre C.
Solution 2 coderek
Solution 3 Jingguo Yao