Hey working on the functional test for Stock Price Checker. When I run it I am getting a res.status of 500 on all the test, but when i run it directly in a browser I get the correct responses. Any help or suggestions would be greatly Appreciated.
I have this exact same problem. Does anyone have an idea what could be causing the issue?
I figured out the problem with my code. The reason my functional tests were failing with a 500 error code status was because a line was failing in my routes/api.js file which I was using to get the user’s IP address. I extracted the user’s IP address using the ‘x-forwarded-for’ property of request.headers. This worked fine when testing manually but it is undefined when the functional tests run. So I’ve modified the code to check first whether this property is defined before trying to use it.
I spotted the error by printing the test response object to the console. The error message was stored in the ‘text’ property of the response object.
@Juwdohr, you might have a different issue but I suspect that if you print the response object to the console you might be able to see what is going on in your case.
So i found that glitch is hiding behind a proxy and you can use
app.enable('trust proxy'); to actually use
req.ip instead of the
req.headers['x-forwarded-for']. This solved my issue all together.