Design the Model

The model-related functions are the only functions that will interact with the database. We need four functions: an all function to get all the tasks from the database, a get to fetch a task with an id, an add to insert a task, and a delete to remove a task. We identified a few tests related to these functions in the test list. Before we can write them, we have to set up a connection to the database in a new task-test.js file.

Since the model functions update a database, we’ll run into an issue with repeating the tests if we’re not careful. Suppose we perform an add task on an empty database. Now we can verify that the number of persistent records is 1. If we run the test again, the test would fail since the count is no longer ...

Get Test-Driving JavaScript Applications 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.