Tell us what’s happening:
I am working on the freeCodeCamp Build a Personal Profile App challenge. All tests pass except test #6: “The /api/profile route should return a JSON response with the correct content type.”
I verified the actual HTTP response using curl and Node’s fetch(). It returns:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
And:
response.headers.get(“content-type”)
// “application/json; charset=utf-8”
However, the challenge test currently appears to use:
const headers = response.headers;
assert.include(headers["content-type"], "application/json");
With Node’s Fetch API, response.headers is a Headers object, so headers["content-type"] is undefined. The correct way to retrieve it is:
response.headers.get("content-type")
Could you please confirm whether this is an issue with the test?
Your code so far
My route uses Express res.json():
app.get(“/api/profile”, (req, res) => {
res.json({
name: “Camper Bot”,
hobbies: [“cycling”, “boating”, “guitar”],
skills: [“JavaScript”, “Node.js”, “Express.js”]
});
});
Tests #1–#5 and #7–#9 pass. Only #6 fails with undefined and string.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Challenge Information:
Build a Personal Profile App - Build a Personal Profile App