This seems a bit weird to me. I'm trying to test an actual (ie. real network) request with Jest.
These are the tested scenarios:
node
terminal <--- This worksWhat could be the reason behind this behavior? And what is the solution?
//This WORKS
test('testing no headers', () => {
return axios.get('http://api.fixer.io/latest')
.then( res => console.log(res) )
});
//This DOES NOT work
test('testing no headers', () => {
return axios.get('http://localhost:3000/users/4/profile',
{headers:{authorization:`Bearer ${mytoken}`}})
.then( res => console.log(res) )
});
//...
//Node Terminal
//This WORKS
> axios.get('http://localhost:3000/users/4/profile',
{headers:{authorization:`Bearer ${mytoken}`}})
.then( res => console.log(res) )
It can be a Jest configuration issue. I solved forcing "node" as jest environment in package.json:
"jest": { "testEnvironment": "node" }
see docs: https://facebook.github.io/jest/docs/configuration.html#testenvironment-string