Making assertions about the length of the Todos collection

Now, we can fetch from the database and make some assertions about the length of the Todos collection. I'm going to use Todo.find to fetch every single Todo inside of the collection. Then, I'll tack on a then callback, so I can do something with that data. In this case, I'll get the todos, and I'm going to assert something about its length. We're going to expect that todos.length equals toBe the number 0.

Todo.find().then((todos) => {
  expect(todos.length).toBe(0);
});

There should be no Todos in the database before this test case runs, and since we're sending in bad data, this test case should not create any Todos. We can now call done and we can also tack on our catch callback, which ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.