...
/Mocking Arbitrary Imports: Continued
Mocking Arbitrary Imports: Continued
Continue developing the persistence feature, and explore mocks in greater depth.
We'll cover the following...
Where we left off
In the last lesson, we introduced a new persistence feature to our app, and wrote an integration test for it. The test boils down to:
- Create a task.
- Refresh the page.
- Make sure the task is there.
- Mark task as completed.
- Refresh the page.
- Make sure it stays completed.
Next, we will write unit tests that validate each step of that scenario.
API functions
Since we have set up json-server
, our trusty backend, we will need to interface with it. I suggest that we first test and create helper functions to make API requests. We will put them in /api/index.js
. That means their tests will be under /api/index.test.js
. Go ahead and create this file, but leave it empty for now.
Let us take a step back, and think about what we want our API functions to do. To begin with, we will need three functions:
createTask
: To create