URL Shortener Not Passing Tests

Here’s my URL shortener https://fcc-urlshortener.pcwcfa.repl.co/api/shorturl. The tests state that the last three of the four tests do not pass. I see for example that the test www.example.com should respond with an {error: ‘invalid url’}, and my app is doing so. By the way, the res.json automatically puts double quotes around both the key and the value, so the actual response is {“error”: “invalid url”}. I hope this is the cause of the tests not passing.


I’m not as far as you are in the FCC curriculum but found this older post;

1 Like

Right, that isn’t an issue. The double quotes show up because it is being converted to JSON, where all properties and string values are wrapped in double quotes. It won’t matter how your JS object is written (single/double quotes, quotes around properties or not), it will always end up the same in JSON.

I see for example that the test www.example.com should respond with an {error: ‘invalid url’}, and my app is doing so.

Is it?

This is the response I’m getting on your page.


And when I try to run the test suite and look at the network tab of the browser dev tools (which you should learn how to do), I see that you are getting CORS errors for those tests:

You’ll need to figure out how to handle that.

1 Like

Thanks. I’ll look into that.

Thanks. I’ll check this one out as well.


I see the CORS error as well. I found the root cause. I had moved the below line from the boilerplate to the end, so the tests couldn’t access my server.


1 Like

I do have one remaining question about the final test using http://www.example.com. I realized the reason for why I was able to get {error: “invalid url”}. It was because I had a trailing space after the URL in my own test. When I typed in the correct http://www.example.com sans the trailing space, I see that the response is that it is a valid URL. However, I don’t think this is an error because both the dns-lookup and my opening a new tab shows that http://www.example.com is now a valid site. I believe the test needs to be updated to use an invalid site. Ex: http://asdfasdfasfdasdf.

lookup err null address 2606:2800:220:1:248:1893:25c8:1946

Sorry, I didn’t read that closely enough:

If you pass an invalid URL that doesn’t follow the valid http://www.example.com format, the JSON response will contain { error: 'invalid url' }

The issue is if it doesn’t fit that pattern. If you open up the network tab, you can see the actual invalid url that is being used to test. Or just pass it jibberish.

But it seems a moot point now because you seem to be passing.

1 Like


Thank you for taking the time to respond. It was very helpful.