Testing GET /todos
With our GET /todos
route now in place, it is time to add a test case for it. Now, before we can actually write the test case, we have to deal with a different problem. The first thing we do inside of our server.test
file is delete all the Todos, and this happens before every single test. The GET /todos
route pretty much lives off the fact that there are Todos it can return. It will handle Node Todos, but for our test case, we want some data in that database.
In order to add this data, what we're going to do is modify beforeEach
, adding some seed data. This means that our database is still going to be predictable; it's always going to look exactly the same when it starts, but it will have some items in it.
Adding seed data for the GET /todos test case
Now, in order to do that, the first thing that we're going to do is make up an array of dummy Todos. These Todos only need the text
property since everything else is going to get populated by Mongoose. I can create a constant...