Learn
Model Testing Patterns
Review
You have developed a model using TDD!
- The model layer represents entities and interactions in a web app’s problem domain.
- Model paths can be test-driven using validators. Call
validateSync
and make assertions on the properties of[instance].errors.[path]
. - The storage of data can be tested with construction and updating methods like
save
andupdate
. Retrieval can be tested with query methods likefind
,findOne
, andfindby
. - Static methods are stored in
[schema].statics
and instance methods are stored in[schema].methods
. Both can be tested like any other JavaScript function.
To learn more about Mongoose, read the guide and refer to the API docs as needed.