- Advanced Node.js Development
- Andrew Mead
- 112字
- 2021-08-27 19:06:07
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.