Testing Custom React Hooks

Learn to test custom React Hooks in this lesson.

Starter project

The project for this lesson contains a HomePage component that uses a custom hook, useTitle, to set the document title to "My App - Home". In this lesson, we’ll create a test for useTitle.

A copy of the project is in the code widget below. Clicking the “Run” button executes the tests.

export default "test-file-stub";
Incomplete code

First attempt

Create a test file adjacent to useTitle.js in the src/common folder called useTitle.test.js. Add ...

Access this course and 1400+ top-rated courses and projects.