Search⌘ K
AI Features

Creating a Manual Shared Module Mock

Understand how to manually mock shared modules in Jest by creating a __mocks__ folder with stub implementations. Learn to apply these mocks across multiple test files to isolate component dependencies on common modules like data.js, ensuring tests pass and improve maintainability in React testing.

Starter project

The project for this lesson is similar to the one in the last lesson. It contains a test to verify a Hello component renders a user’s name and a test to verify a YouAre component renders a user’s role. The components have a dependency on a common data.js module. The tests on the components are in different files, and the tests currently fail.

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