Getting Tests to Clear the DB
Understand how to maintain a clean database state between integration test runs in your React application. This lesson teaches you to create and use scripts to reset the database, preventing test failures caused by data pollution and ensuring accurate test results. You'll learn practical steps for both macOS/Linux and Windows environments to automate this process and ensure consistent integration testing.
We'll cover the following...
We are almost done fixing the integration test for the persistence feature. As you recall, we:
- Wrote an integration test that verifies that tasks persist between sessions
- Wrote unit tests for API functions and the
useTaskshook, which implements the required features - Implemented the API functions and the
useTaskshook.
Now we just need to make use of this hook in App.js, and the test should pass:
// /src/App.js
import React from 'react';
import TaskInput from './components/TaskInput';
import TaskList from './components/TaskList';
import useTasks from './hooks/useTasks';
import './App.css';
function App() {
const [tasks, {createTask, toggleTask}] = useTasks();
return (
<div>
<TaskInput onSubmit={createTask}/>
<TaskList tasks={tasks} onToggleTask={toggleTask}/>
</div>
);
}
export default App;
Note: You do not need to have the
App.cssimport. You just add it to ease testing.
Hotfix
Upon reaching this section, I realized that I made a small mistake that you undoubtedly followed. It ...