...

/

Mocking Axios

Mocking Axios

In this example, we send a mock request to Axios.

We'll cover the following...

Before we move on to the actual tests, we have to lay out some infrastructure to mock the axios library. With Jest, we can create overrides for any imported library using the built-in mocking features.

We need to create a __mocks__ directory at the same level in the project as the node_modules directory. Inside we can place files named to override any Node package. For example, the axios.js file will override import axios from 'axios' in our project.

Next, we ...