Book Image

Node Web Development - Second Edition

By : David Herron
Book Image

Node Web Development - Second Edition

By: David Herron

Overview of this book

Table of Contents (17 chapters)
Node Web Development Second Edition
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Testing a model


Let's start our journey of using the Notes application to explore testing with the data models. Because this is unit testing, the models should be tested separately from the rest of the Notes application.

That would, in the case of the models, mean creating a mock database object. To test a data model and not mock out the database means that for the test to run, the database server must be running, making it a dependency of the test. However, in this case it would mean creating a fake Sequelize library, which does not look like a productive use of our time. One can also argue that testing a data model really means you're testing the interaction between your code and the database, and that mocking out the database means not testing that interaction.

Therefore we are going to skip creating a mock database module, and test the model against a real database server. Instead of running the test against the live production database, it should be run against a test database that contains...