Search⌘ K
AI Features

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:

  1. Wrote an integration test that verifies that tasks persist between sessions
  2. Wrote unit tests for API functions and the useTasks hook, which implements the required features
  3. Implemented the API functions and the useTasks hook.

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.css import. 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 ...