O'Reilly logo

Node Web Development - Second Edition by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required