I'm trying to write a test using React-lIbraries and Jest.
The test should render a mock axios that produces the mock data I've interested but I keep having the following error:
TypeError: _axios.default.get.mockResolvedValueOnce is not a function
Below is my test code:
import axios from 'axios'
import Home from '../pages/index'
afterEach(cleanup)
const response = [...
]
test('Should render a list of items', async () => {
axios.get.mockResolvedValueOnce({ data: response })
render(
<Home />
)
await waitFor(() => expect(axios.get).toHaveBeenCalled())
response.forEach(item => {
const element = screen.getByText(products.title)
expect(element).toBeInTheDocument()
})
})