Closed serverlesspolska closed 4 years ago
Possible duplicated: https://github.com/axios/axios/issues/1418
Thanks @OpenGG . adding const adapter = require('axios/lib/adapters/http')
to the config solved the problem for me
I also had this problem. This thread led me to this part of the Jest docs. I was able to fix the issue by pasting:
/**
* @jest-environment node
*/
At the top of my test file. FWIW, adding:
{
// ...
"testEnvironment": "node"
//...
}
to either jest.config.js
or to my package.json
file did not work for some reason. Not sure why...
I also had this problem. This thread led me to this part of the Jest docs. I was able to fix the issue by pasting:
/** * @jest-environment node */
At the top of my test file. FWIW, adding:
{ // ... "testEnvironment": "node" //... }
to either
jest.config.js
or to mypackage.json
file did not work for some reason. Not sure why...
really thanks, this solves my problem
I solved this problem with the answer in the link below.
I also had this problem. This thread led me to this part of the Jest docs. I was able to fix the issue by pasting:
/** * @jest-environment node */
At the top of my test file. FWIW, adding:
{ // ... "testEnvironment": "node" //... }
to either
jest.config.js
or to mypackage.json
file did not work for some reason. Not sure why...
thanks very much! I use it in package.json
:
{
"scripts": {
"test": "jest --env=node"
}
}
I don't think the solution above is complete, often you will actually want to run your tests in the jsdom environment, if testing UI
If using jest, users can set testURL to avoid CORS problem.
My jest.config.js resolves this issue (note testEnvironment without quotes):
module.exports = { "transform": { "^.+\\.(ts|tsx)$": "ts-jest" }, testEnvironment: 'node' }
Adding anything in my jest config was making other tests fail so adding the line below to my beforeAll function in my tests and it fixed the CORS error.
axios.defaults.adapter = require('axios/lib/adapters/http');
Added testEnvironment variable in the Jest.config file within module.exports
module.exports = {
rootDir: "../../",
transform: {"^.+\.tsx?$": "ts-jest"},
setupFiles: ["./config/pact/pactSetup.ts"],
moduleFileExtensions: ["ts", "js"],
moduleNameMapper: {
"^@src/(.)$": "
It resolved the issue.
Hi All,
I've got lambda function which I access via API Gateway. This function works ok when I test it via Postman or via this test which uses
request
library:Problem
Unfortunately, when I'm using Axis I get following message Error: Cross origin http://localhost forbidden.
Could you please tell me what am I doing wrong?
My code looks like that:
Context