Adding the catch call for the error handling

The catch is going to get any errors that might occur inside of our callback. Then, we're going to be able to take that error argument, and using an arrow function, we're going to be able to pass it into done, just like this:

Todo.find().then((todos) => {
  expect(todos.length).toBe(1);
  expect(todos[0].text).toBe(text);
  done();
}).catch((e) => done(e));

Notice here I'm using the statement syntax as opposed to the arrow function expression syntax. With this in place, our test case is now good to go. We have a great test case, and all we need to do is set up the scripts in package.json to actually run it.

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.