In the URL-Shortner project for validating the url I was using the code
if(!url.protocol.includes(‘http’)) return res.status(400).send({“error”: ‘invalid url’})
and it was failing all the time
until I thought to delete the .status(400) and the test passed like a charm
Is there any specific reason for it?? [ it had me setting on it for 2 days ]
The part that caused your problem is the res.ok which is only true if the response status is in the 200’s. I had the same problem. If you look at the list of 400 error codes, asking for an invalid URL doesn’t really fit any of them as it’s a valid request and successfully gets a valid, albeit negative, response.