I\'m trying to write unit tests for parts of my Node app. I\'m using Mongoose for my ORM.
I\'ve searched a bunch for how to do testing with Mongoose and Node but not com
I solved this by structuring my code a little. I'm keeping all my mongoose-related stuff in separate classes with APIs like "save", "find", "delete" and no other class does direct access to the database. Then I simply mock those in tests that rely on data.
I did something similar with the actual objects that are returned. For every model I have in mongoose, I have a corresponding class that wraps it and provides access-methods to fields. Those are also easily mocked.