Writing tests for Node.js server
Let's start writing the tests for the application we built for the backend part of the node
server.
We will be using the following folder structure:

There are two folders inside the test
folder. One for unit testing, called unit
, and another for end-to-end testing, called e2e
. We will start by writing the unit tests, which go under the unit
directory. The naming convention is appending the .spec
part to the filename for every file we will be writing tests for.
Writing tests for controllers
Let's get started with writing tests for the controllers we added. Create a folder called controllers
inside the test/unit/specs
and create a new file inside it called movies.spec.js
. This will be the naming convention that we will follow while creating the test files for any components: controllers, models, or Vue components—the actual filename followed by .spec.js
. This helps to maintain the readability of the code.
Let's first recap what we have in our movies.js
file:
var...