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 router functions

Now that we've seen a little bit about testing a data model, let's move on to testing the route functions. There is obviously a lot more to test in the Notes data models, such as the user model. Our goal in this chapter is not to produce a complete test suite, but to introduce you to unit testing in Node.

In unit testing the route functions, we have a little more freedom in mocking out the other modules. We can fairly easily create a faux data model, and can even bypass Express completely. Let's see how it's done.

Let's start with the faux data model. It can also be used as an in-memory data model in the Notes application, if you like. In the test directory, create a file named mock-model.js containing the following:

var ...

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