Test spies
In this section, which is the final section for the testing chapter, we'll learn some pretty advanced testing techniques. We'll be using these techniques as we build real-world apps, but for now let's start off with an example. We'll worry about the vocabulary for what we're about to do in just a second.
For the moment, we'll close all our current files and create a new directory in the root of the project. We'll make a new folder called spies
. We'll talk about what exactly spies
are and how they relate to testing in just a moment. Inside spies
, we'll make two files: app.js
(this is the file that we'll be testing) and a second one, called db.js
. In our example, we can just assume that db.js
is a file that has all sorts of methods for saving and reading data from the database.
Inside db.js
, we'll create one function using module.exports
. Let's create a function called saveUser
. The saveUser
function will be a really simple function, and it will take a user
object like this:
module...