Open niet-dev opened 4 years ago
Yes, this is definitely an issue. A weirdish fix for this could be serialize and parse the noteToView
variable like so:
expect(resultNote.body).toEqual(JSON.parse(JSON.stringify(noteToView)))
This is basically what happens in the route handler anyway, but definitely requires as explanation.
Problem
In part 4b, the section Error handling and async/await contains a test that will fail:
Specifically, Jest will take issue with the way the note's date is formatted:
I'm not a Javascript wizard (hence why I'm taking this course), but it seems like Express really wants to parse the date field as a string, whereas MongoDB will return a raw Date as expected.
Proposed Solution
Modify the noteSchema's toJSON() transform to convert the date to a string when necessary:
Or, maybe I'm dumb and missed something in the text. Either way wanted to bring this up.