Exercise tracker project - test not passing despite data being correct

I’m still experiencing the same issue where the test
The `date` property of any object in the `log` array that is returned from `GET /api/users/:id/logs` should be a string.. Use the `dateString` format of the `Date` API.
does not pass despite the data being correct. The tests output is:

{"username":"fcc_test_16474427368","_id":"1647442736919","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427373","_id":"1647442737418","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427378","_id":"1647442737952","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427384","_id":"1647442738518","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427389","_id":"1647442739012","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427393","_id":"1647442739509","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427398","_id":"1647442740001","log":[{"description":"test","duration":60,"date":"Thu Jan 01 1970"}],"count":1}
{"username":"fcc_test_16474427404","_id":"1647442740508","log":[{"description":"test","duration":60,"date":"Mon Jan 01 1990"},{"description":"test","duration":60,"date":"Wed Jan 03 1990"}],"count":2}
{"username":"fcc_test_16474427404","_id":"1647442740508","log":[{"description":"test","duration":60,"date":"Mon Jan 01 1990"}],"count":1}
{"username":"fcc_test_16474427404","_id":"1647442740508","log":[{"description":"test","duration":60,"date":"Mon Jan 01 1990"}],"count":1}

Link to my code
My OS:
macOS Monterey Version 12.2.1
My Browser:
Google Chrome Version 99.0.4844.51 (Official Build) (x86_64)

const formattedDate = new Date(date || null).toDateString();

null gets coerced to 0

new Date(null)
// Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)
new Date(0)
// Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)

Thank you very much for your help, this fixed the issue. Much appreciated!
I have to report though that the test and its description are completely unrelated to the cause of the problem and utterly confusing.
Is there any we could examine the tests’ source code to check what is being tested exactly?

I agree, the test message isn’t super helpful. It does both a type and content check but the message makes it sound like it’s just a type check.

You can find the tests for the Back End Development and APIs in the main freeCodeCamp repo (exercise-tracker). You can find all tests somewhere in one of the freeCodeCamp repositories (where exactly depends).

1 Like